Reputation: 1721
I have a SAS dataset that is at least about 100MB+. I am trying to read it into R. I found of the following.
sas7bdat package
read.sas7bdat
But I am looking into to see if this is the common way that is used? Or if there could be another way that is recommended?
Another approach I am trying is to convert sas7bdat to csv, but if I did it - are there any potential issues I should be aware of? Thank you.
Upvotes: 1
Views: 3617
Reputation: 11
Simple solution
library(haven)
datain <- read_sas("filename.sas7bdat", NULL)
Or you can cheat and click and point in RStudio
Upvotes: 0
Reputation: 4206
If you want to access your SAS data with something other than SAS, it's generally good practice to use the XPORT engine to export it as a "transport file" (extension: .xpt
or .xport
). SAS intends this file format to be independent of operating environment (see here), so it can be used by other software.
In contrast, .sas7bdat
files are designed only to be used by SAS. Reading them into R necessarily depends on having a licensed version of SAS on your computer or (as in the case of the sas7bdat package you mentioned) reverse engineering a solution. For people stuck with a .sas7bdat
file and no SAS license, you can try downloading a free trial of Stat/Transfer.
Once you have the .xpt
file, you can read it into R like this:
require(foreign)
read.xport("path/to/file/data.xpt")
There are other perfectly good solutions for reading in .xpt
files, like sas.get()
(Hmisc package) and read.ssd
(foreign package), but they can be harder to implement. The SASxport package is a newer attempt to improve on the solution I just gave above, but I can't vouch for it yet.
Upvotes: 1