Run SAS code in R

Hello,

I am trying to run some SAS programs directly from R. I have found some possible solutions, but they have not worked for me. Any help would be greatly appreciated. Here are the examples that I have tried.

Method 1: Using a shell to run a SAS program in R.

setwd("C:\\Program Files\\SASHome2\\SASFoundation\\9.4\\")
return.code <- shell("sas.exe -SYSIN C:\\test\\Edit_SAS.sas")

A SAS window opens giving this error regarding the SAS log.

Method 2: Using a SAS engine in R and code chunks:
Below is an example to print out “Hello World”, suggested on another forum:

engine.path = 'C:\\Program Files\\SASHome2\\SASFoundation\\9.4\\sas.exe'
```{sas}
data _null_;
put 'Hello, world!';
run;
(there are 3 ` symbols here)

This does not run. But a warning is visible in RStudio that says that the symbol, `, is an “invalid token”


Thanks for your consideration.
-Fraser

With the second method, are you running this in a .R, .Rmd, or .qmd file? I think you only have a shot of it working in a .Rmd file.

Take a look at: CRAN - Package SASmarkdown

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.