将 Pandas 数据帧导出为 SAS sas7bdat 格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49235845/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 05:18:45  来源:igfitidea点击:

Export pandas dataframe to SAS sas7bdat format

pandassas

提问by BogdanC

The flow I have in mind in this:
1. Export a sas7bdat from SAS
2. Import that file in python with pd.read_sasand do some stuff on in
3. Export the pandas dataframe to sas7bdat (or some other SAS binary fileformat). I thought that pd.to_saswould exist, but it doesn't
4. Open the new file in SAS and do further stuff on it

我想到的流程是:
1. 从 SAS 导出 sas7bdat
2. 在 python 中导入该文件pd.read_sas并在
3. 将 Pandas 数据帧导出到 sas7bdat(或其他一些 SAS 二进制文件格式)。我认为这pd.to_sas会存在,但它不存在
4. 在 SAS 中打开新文件并对其进行进一步操作

Is there a solution to point 3 above? As I see it, my only options are csv or some SQL database.
This is not really a programming question. hope it won't be an issue.

上面第 3 点有解决方案吗?在我看来,我唯一的选择是 csv 或一些 SQL 数据库。
这不是一个真正的编程问题。希望这不会成为问题。

回答by Joe

Python is capable of writing to SAS .xpt format (see for example the xport library), which is SAS's open file format. SAS7BDAT is a closed file format, and not intended to be read/written to by other languages; some have reverse engineered enough of it to read at least, but from what I've seen no good SAS7BDAT writer exists (R has haven, for example, which is the best one I've seen, but it still has issues and things it can't do).

Python 能够写入 SAS .xpt 格式(例如参见xport 库),这是 SAS 的开放文件格式。SAS7BDAT 是一种封闭的文件格式,不能被其他语言读/写;有些人已经对其进行了足够的逆向工程,至少可以阅读,但从我所看到的,不存在好的 SAS7BDAT 编写器(例如,R 有一个我见过的最好的一个,但它仍然存在问题和事情做不到)。

More common than XPT files, though, which can be slow to work with, is to write a CSV and then write a SAS input script in your python/etc. program. That allows you to use variable labels, value labels, types, etc., as you wish very easily; and writing a SAS input script is very easy to do. Many other software packages do this for their preferred method to produce SAS files. This has an additional advantage that it is easily cross-platform - doesn't matter if your SAS program is on a mainframe, UNIX, Windows, etc.; it's all the same.

但是,比 XPT 文件更常见的是编写一个 CSV 文件,然后在你的 python/etc 中编写一个 SAS 输入脚本。程序。这使您可以非常轻松地使用变量标签、值标签、类型等;编写 SAS 输入脚本非常容易。许多其他软件包这样做是因为它们首选的方法来生成 SAS 文件。这还有一个额外的优势,那就是它很容易跨平台——不管你的 SAS 程序是在大型机、UNIX、Windows 等上;全部都是一样。