spinsas
is an alternative way of processing dynamic
Markdown from a SAS command file. In this form, documents are written
within the comments of a SAS file. This enables you to run the same file
within SAS (to simply execute the commands) and through
knitr
(to produce Markdown and HTML files).
This is particularly useful if you already have a number of *.sas files to which you'd like to add a little text to produce a document.
Within your SAS command file (*.sas), you use the following symbols to denote plain Markdown text, SAS code chunks, R code chunks, and text to be dropped from the document.
Notice that SAS will treat all of these as comments.
In order to run SAS code, first we load the SASmarkdown
library so it can automatically set up some necessary options in R.
*+ setup, message=FALSE ;
*R
library(SASmarkdown)
;
Text is then included as a special comment.
** The report begins here.;
Finally, the executable SAS code is given a line of chunk instructions.
*+ example1, engine='sas', comment=NA;
proc means data=sashelp.class /*(keep = age)*/;
run;
/* lines here are
ignored by SAS. If at the end of
your SAS code chunk they must be followed by a semi-colon.
*/
;
You can use the usual Markdown within the text sections.
The entire document might be:
*+ setup, message=FALSE ;
*R
library(SASmarkdown)
;
** The report begins here.;
*+ example1, engine='sas', comment=NA;
proc means data=sashelp.class /*(keep = age)*/;
run;
Set up an example file to use:
<- "
indoc *+ setup, message=FALSE ;
*R
library(SASmarkdown)
;
** The report begins here.;
*+ example1, engine='sas', comment=NA;
proc means data=sashelp.class /*(keep = age)*/;
run;
"
writeLines(indoc, "indoc.sas")
To process this document then, simply use
library(SASmarkdown)
spinsas("indoc.sas")
Which gives a document, "indoc.html" that looks like
library(SASmarkdown)
The report begins here.
proc means data=sashelp.class /*(keep = age)*/;
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
-------------------------------------------------------------------------