简体   繁体   English

使用R / Python将SAS文件(sas7bdat)转换为平面文件而无内存限制

[英]Convert SAS file (sas7bdat) to a flat file using R/Python without memory constraints

I need to convert a SAS file into a flat file. 我需要将SAS文件转换为平面文件。 These files can be pretty big that can go up to 60 GB in size. 这些文件可能很大,最大可以达到60 GB。 I wrote a script in R (below) but it reads the entire data and then exports to a CSV file. 我在R(如下)中编写了一个脚本,但它读取了所有数据,然后导出到CSV文件。 Is there a way I could convert such big files without any memory constraints. 有没有办法可以转换这么大的文件而没有任何内存限制。 I am open to using either R or Python. 我愿意使用R或Python。 I working on a machine that has 16 GB RAM. 我在具有16 GB RAM的计算机上工作。

args = commandArgs(trailingOnly=TRUE)

library(sas7bdat)

MyData <-  read.sas7bdat(file = args[1])
write.csv(MyData, file = args[2], row.names = FALSE)

In my opinion, you can aquire solution using pandas.read_sas and chunksize arg: 我认为,您可以使用pandas.read_sas和chunksize arg获取解决方案:

Pandas read sas docs 熊猫阅读SAS文档

For example, iterate through 10k observations: 例如,迭代进行1万次观察:

import pandas as pd

chunk_size =  10**4
for chunk in pd.read_sas(filename, chunksize=chunksize):
    process(chunk)

where process() are instructions which you want to provide (append, etc.). 其中process()是要提供(附加等)的指令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM