[SAS workshop notes | SAS Markdown]
The SASmarkdown package contains several alternative SAS engines, and some helper functions to use with them. It adds to the functionality already in the knitr
package.
To install the very latest version of SASmarkdown, use
install.packages("https://www.ssc.wisc.edu/~hemken/SASworkshops/SASmarkdown.tar.gz", repos=NULL, type="source")
You can also install the SASmarkdown package from CRAN as you would any R package. In Rstudio you can do this from the Packages pane, or in the Console type:
install.packages("SASmarkdown", type="source")
The latter is preferred, because it also installs the vignettes.
(This package can also be found at http://github.com/Hemken/SASmarkdown .
You can suggest changes or report bugs there.)
For the R documentation, type
help(package="SASmarkdown")
For basic usage information, the "User guides, package vignettes" found via help
ought to be the best place to start (or keep reading here).
To load and use the SAS engines, use the R library
function in an preliminary code block in your document.
```{r libload}
library(SASmarkdown)
```
library(SASmarkdown)
## SAS found at C:/Program Files/SASHome/SASFoundation/9.4/sas.exe
## sas, saslog, sashtml, sashtmllog
## sashtml5, & sashtml5log engines
## are now ready to use.
When you load the SASmarkdown package, six SAS engines are defined and ready to use. They all run your SAS code, but return different output into your document. These are
sas - this returns the SAS code you ran and ordinary ("listing") output
saslog - this returns the SAS log instead of your code, and ordinary SAS output
sashtml - this returns SAS code and SAS HTML output
sashtmllog - this returns the SAS log and SAS HTML output
sashtml5 - this returns SAS code and SAS HTML output with inline graphics
sashtml5log - this returns the SAS log and SAS HTML output
These engines all require the location of SAS on your computer. In addition, you can set command line options for SAS to use.
When you load SASmarkdown via library
you will see a message telling you that the SAS executable was found, or that SAS was not found.
If SAS was not found you need to specify the executable location yourself. You only need to set the engines you will be using.
This might be done like this:
saspath <- "C:/Program Files/SASHome/SASFoundation/9.4/sas.exe"
sasopts <- "-nosplash -ls 75"
knitr::opts_chunk$set(engine.path=list(sas=saspath, saslog=saspath),
engine.opts=list(sas=sasopts, saslog=sasopts),
comment=NA)
You can use these SAS engines in much the same way as any language engine in knitr
. In your document include a code block like this:
```{sas sas-ex}
proc means data=sashelp.class;
run;
```
Which gives us
proc means data=sashelp.class;
run;
The MEANS Procedure
Variable N Mean Std Dev Minimum Maximum
-------------------------------------------------------------------------
Age 19 13.3157895 1.4926722 11.0000000 16.0000000
Height 19 62.3368421 5.1270752 51.3000000 72.0000000
Weight 19 100.0263158 22.7739335 50.5000000 150.0000000
-------------------------------------------------------------------------
For more explanation and examples, please see SAS and R Markdown
Written using