I have a 60gb sas7bdat file I am trying to subset in R. Does anyone know a method to do this?
I have SAS and it takes about 14 minutes to complete, but I want a way to do this in R.
thank you
I downloaded the wonderfull dsread http://www.oview.co.uk/dsread/ that converts Sas to csv.
You should use it from the CMD but I choose to integrate this in R. I created a function that migrate Sas to csv:
esp_Sas_Csv<-function(dir,file_input,dir_output,device="c:") {
p1<-paste("cd",dir)
if(tolower(device)!="c:") {p1<-paste(device,"\n",p1)}
#"open" the program
p2<-"SET dsread=C:\\dsread\\dsread.exe"
cmd2<-paste('"%dsread%" /v /t ',file_input,' > "',dir_output,file_input,'.csv"',sep="")
cmd<-paste(p1,p2,cmd2, sep="\n")
setwd("c:\\temp")
write(cmd,"sas_to_csv.bat")
system("sas_to_csv.bat")
}
This code:
device<-"c:"
dir<-"C:\\temp\\"
file_input<-"my_sas_tab"
dir_output<-"C:\\temp\\"
esp_Sas_Csv(dir,file_input,dir_output,device)
generates and Runs a .bat like
cd C:\temp\
SET dsread=C:\dsread\dsread.exe
"%dsread%" /v /t my_sas_tab > "C:\temp\my_sas_tab.csv"
See my answer here--
I found the haven package to work reasonably quickly in reading sas7bdat files.
Anyway, at 60GB, your best bet is probably to convert it to .csv or something fread can handle, then data.table::fread it into R.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With