Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read large SAS data in R [closed]

Tags:

r

sas

I have a sas7bdat data set of 2GB which i want to read in R. I am using sas7bdat package to read the dataset but after using read.sas7bdat,there is no response from R and it keeps on running for hours without any output.

I have tried using sas7bdat and haven package also. Can anyone help me read the data in R quickly.

like image 383
Mayur Avatar asked Sep 27 '22 00:09

Mayur


1 Answers

Example

/* SAS */
libname rdata "C:/tmp";
data rdata.test; 
    input x y;
    datalines;
 5 6
 7 8
 ;
 run;

# R
setwd("C:/tmp")

# install.packages("haven")
library(haven)
test <- read_sas("test.sas7bdat")

The read_sas function in the haven package should be much faster than the sas7bdat package's functions. As per Hadley's GitHub description:

Can read SAS's proprietary binary format (SAS7BDAT). The one other package on CRAN that does that, sas7bdat, was created to document the reverse-engineering effort. Thus its implementation is designed for experimentation, rather than efficiency. Haven is significantly faster and should also support a wider range of SAS files (including compressed), and works with SAS7BCAT files.

like image 140
nathanesau Avatar answered Oct 30 '22 11:10

nathanesau