SASmarkdown
November 2022
1 The SASmarkdown Package
1.1 Installation
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.
You can install the SASmarkdown package from CRAN as you would any R package. The current version on CRAN is SASmarkdown 0.8.0. In Rstudio you install from the Packages pane, or in the Console type:
install.packages("SASmarkdown")
This package can also be found at http://github.com/Hemken/SASmarkdown . (You can suggest changes or report bugs there.)
To install the latest version of SASmarkdown, use
remotes::install_github("Hemken/SASmarkdown")
Alternatively, use
install.packages("https://www.ssc.wisc.edu/~hemken/SASworkshops/SASmarkdown_0.8.0.tar.gz",
repos=NULL, type="source")
# or, for Windows
# install.packages("https://www.ssc.wisc.edu/~hemken/SASworkshops/SASmarkdown_0.8.0.zip",
# repos=NULL)
For the R documentation, type
help(package="SASmarkdown")
For basic usage information, keep reading here.
1.2 Set up the SAS Engines
To load and use the SAS engines, use the R
library
function in an preliminary code block in
your document.
```{r}
library(SASmarkdown)
```
In your document this would look like:
library(SASmarkdown)
## SAS found at C:/Program Files/SASHome/SASFoundation/9.4/sas.exe
## SAS engines are now ready to use.
When you load the SASmarkdown package, eight SAS engines are defined and ready to use. They all run your SAS code, but return different output into your document. These are used in pairs.
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
saspdf - this returns SAS code and SAS LaTeX output with PDF graphics
saspdflog - this returns the SAS log and SAS LaTeX output
1.3 Use an Engine
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" # '-nosplash' fails in Unix terminals
knitr::opts_chunk$set(engine.path=list(sas=saspath, saslog=saspath),
engine.opts=list(sas=sasopts, saslog=sasopts),
comment=NA)
1.3.1 "sas" engine
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}
proc means data=sashelp.class;
run;
```
Which gives you
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 continue with chapter 2.
Written using
- SASmarkdown version 0.8.0.
- knitr version 1.40.
- R version 4.2.2 (2022-10-31 ucrt).