Installing & Using the SASmarkdown Package

Doug Hemken

February 2020

[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("", 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 .
You can suggest changes or report bugs there.)

For the R documentation, type


For basic usage information, the "User guides, package vignettes" found via help ought to be the best place to start (or keep reading here).

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 libload} 
## 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

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"
knitr::opts_chunk$set(engine.path=list(sas=saspath, saslog=saspath),
                      engine.opts=list(sas=sasopts, saslog=sasopts), 

"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 sas-ex} 
proc means data=sashelp.class;

Which gives us

proc means data=sashelp.class;
                            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

  • SASmarkdown version 0.5.2.
  • knitr version 1.28.
  • R version 3.6.2 (2019-12-12).