This discussion assumes you already have a basic understanding of Markdown for document formatting, Rmarkdown to include executable code in a document, and SAS to write the code.
This depends on your operating system, the version of SAS, and whether or not you have SAS installed in the default location. This example catches both Windows and linux SAS for me.
require(SASmarkdown)
if (file.exists("C:/Program Files/SASHome/SASFoundation/9.4/sas.exe")) {
saspath <- "C:/Program Files/SASHome/SASFoundation/9.4/sas.exe"
} else {
saspath <- "sas"
}
sasopts <- "-nosplash -ls 75"
A simple code chunk in Rmarkdown might look like:
```{r example1, engine="sas", engine.path=saspath, engine.opts=sasopts, comment=""}
proc means data=sashelp.class (keep = age);
run;
```
And in your document this would produce:
proc means data=sashelp.class (keep = age);
run;
The MEANS Procedure
Analysis Variable : Age
N Mean Std Dev Minimum Maximum
------------------------------------------------------------------
19 13.3157895 1.4926722 11.0000000 16.0000000
------------------------------------------------------------------
Switch the "engine" to sashtml.
This example also reuses the previous code chunk by using the same chunk label, "example1", and suppresses the code echo with the "echo=FALSE" chunk option.
```{r example1, engine="sashtml", engine.path=saspath, engine.opts=sasopts, comment="", echo=FALSE}
```
Which produces:
If you use the "sashtml" engine, nothing special is required to include SAS ODS graphics.
```{r example2, engine="sashtml", engine.path=saspath, engine.opts=sasopts, comment=""}
proc corr data=sashelp.class nosimple plots=matrix;
run;
```
Producing:
proc corr data=sashelp.class nosimple plots=matrix;
run;
We can repeat the first example, showing the SAS log instead of the SAS code by using the saslog engine.
```{r example1, engine="saslog", engine.path=saspath, engine.opts=sasopts, comment=""}
```
Producing:
2 proc means data=sashelp.class (keep = age);
3 run;
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The PROCEDURE MEANS printed page 1.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.14 seconds
cpu time 0.10 seconds
The MEANS Procedure
Analysis Variable : Age
N Mean Std Dev Minimum Maximum
------------------------------------------------------------------
19 13.3157895 1.4926722 11.0000000 16.0000000
------------------------------------------------------------------
Finally, you can have both the SAS log and the HTML output with the sashtmllog engine.
```{r example1, engine="sashtmllog", engine.path=saspath, engine.opts=sasopts, comment=""}
```
Producing:
6 proc means data=sashelp.class (keep = age);
7 run;
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.04 seconds
cpu time 0.04 seconds