5

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.

Alan Moore
  • 73,866
  • 12
  • 100
  • 156
Mayur
  • 83
  • 1
  • 8

1 Answers1

4

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.

thelatemail
  • 91,185
  • 12
  • 128
  • 188
nathanesau
  • 1,681
  • 16
  • 27
  • "'The read_sas function is supposedly much quicker for the haven package." Source? –  Aug 17 '15 at 06:21
  • see their github. I've updated by post – nathanesau Aug 17 '15 at 06:22
  • Why not adding this in your post, rather as a comment? –  Aug 17 '15 at 06:23
  • I am getting the error message on using read_sas : "Error: Failed to parse C:\Users\Desktop\new_clinical.sas7bdat: Invalid file, or file has unsupported features." – Mayur Aug 17 '15 at 06:28
  • what happens if you try loading the file without the extension. i.e. see [here](https://github.com/hadley/haven/issues/34) – nathanesau Aug 17 '15 at 06:32
  • I am still not able to read the file. Without extension it is giving error as : Error in normalizePath(path.expand(path), winslash, mustWork) : path[1]="D:\Biostatistics\Data\derived\clinical": The system cannot find the file specified – Mayur Aug 18 '15 at 10:41
  • @user3710546 see also my benchmarks: http://stackoverflow.com/a/30043226/3576984 – MichaelChirico Mar 22 '16 at 14:35