Linking SAS code chunks makes use of SAS's autoexec.sas file. When you attach the SASmarkdown library, a chunk option is set up to place chunks in an autoexc file.
library(SASmarkdown)
To have the result of one code chunk available to use in a later code
chunk, set the chunk option collectcode=TRUE
.
In this example, a data set is copied to the WORK library and only one variable is kept.
In Rmarkdown this would look like:
```{sas datastep, collectcode=TRUE}
data class;
set sashelp.class;
keep age;
run;
```
And in your final document it would appear as:
data class;
set sashelp.class;
keep age;
run;
Without collectcode to link the code chunks, a later chunk that referenced the data in the WORK library would produce an error, but this now works. (No special option is needed for this later step.)
proc means data=class;
run;
The MEANS Procedure
Analysis Variable : Age
N Mean Std Dev Minimum Maximum
------------------------------------------------------------------
19 13.3157895 1.4926722 11.0000000 16.0000000
------------------------------------------------------------------