Executing a SAS program in R using system() Command

前端 未结 1 1731
执笔经年
执笔经年 2021-01-03 10:50

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

相关标签:
1条回答
  • 2021-01-03 11:28

    Assuming your sas program generates a sas dataset, you'll need to do two things:

    1. Through shellor 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.

    2. 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!

    0 讨论(0)
提交回复
热议问题