Skip to content
Prev 377040 / 398502 Next

Importing SAS datasets into R efficiently

Hi,

'foreign' will only read SAS XPT files, not the proprietary BDAT files, which I presume is the case here.

I don't use 'haven', but it looks like the key functions are written in C/C++, which should be relatively efficient.

If you are having specific issues with particular files,  because they are rather large, and/or have some kind of complex structure, you might want to communicate directly with the haven maintainers to see if there are some performance bottlenecks that perhaps they can resolve.

The only other option, to my knowledge, to directly read BDAT files in R, is the sas7bdat package on CRAN:

  https://cran.r-project.org/web/packages/sas7bdat/ <https://cran.r-project.org/web/packages/sas7bdat/>

However, it looks like it has not been updated in several years, so not sure of status.

Another alternative, if you have access to SAS, is to export the BDAT datasets(s) to CSV files in SAS, and them import them into R, using read.csv().

Regards,

Marc Schwartz