My company recently converted to SAS and did not buy the SAS SHARE license so I cannot ODBC into the server. I am not a SAS user, but I am writing a program that needs to qu
Assuming your sas program generates a sas dataset, you'll need to do two things:
Through shell
or system
, make SAS run the program, but first cd
in the directory containing the sas executable in case the directory isn't in your PATH environment variable.
setwd("c:\\Program Files\\SASHome 9.4\\SASFoundation\\9.4\\")
return.code <- shell("sas.exe -SYSIN c:\\temp\\myprogram.sas")
Note that what this returns is NOT the data itself, but the code issued by the OS telling you if the task succeeded or not. A code 0
means task has succeeded.
In the sas program, all I did was to create a copy of sashelp.baseball
in the c:\temp
directory.
Import the generated dataset into R using one of the packages written for that. Haven
is the most recent and IMO most reliable one.
# Install Haven from CRAN:
install.packages("haven")
# Import the dataset:
myData <- read_sas("c:\\temps\\baseball.sas7bdat")
And there you should have it!