SASweave: Literate programming using SAS

by Russell V. Lenth, University of Iowa, USA  and  Søren Hjøsgaard, Aarhus University, Denmark

Overview

SASweave, patterned after Sweave (Leisch, 2002), is a way to easily and reliably prepare documents containing SAS code, output, and graphics.  You first prepare a .SAStex source file, which is a LaTeX file with additional environments containing SAS code.  SASweave reads that file, runs the SAS code, and creates a .tex file that includes the SAS code and output in verbatim environments, as well as any graphics that are created.  SASweave can also pass the results directly to pdflatex, creating the formatted document.  For illustration, here is a simple source file and the resulting PDF file.

SASweave can also accommodate Sweave source files, which it passes to R's Sweave function for processing, or source files containing both SAS and R code.  Exactly what to do and what order to do it in is determined by the extension in the name of the source file.

A related operation called tangling is provided by a sastangle utility.  This simply extracts the SAS code from the source file and saves it in a .sas file.

Besides the convenience, another good reason to use SASweave, rather than manually copying and pasting code and output, is that SASweave guarantees that the output you see is the actual result of the code displayed.  Using such utilities to document your work is known as literate programming (a term coined by Donald Knuth, the original author of TeX), whereby code, documentation, and output are all packaged together.

Downloading SASweave

Current version: 1.2.10 (August 21, 2007)
Version 1.2.8 is also published in Journal of Statistical Software, Volume 19, Issue 8.

SAS 9.2 notes

Linux/Unix notes

SASweave uses awk scripts (actually, gawk or nawk are required, because we need the ability to load more than one awk script at a time).  You copy the scripts to a suitable location, the associated shell scripts sasweave and sastangle to a location in the PATH, and the file SasWeave.sty to a location in the TEXINPUTS path.  You will need to edit sasweave and sastangle so that they can find these scripts.

Windows notes

The installer gives you the option of associating SASweave with the filename extensions .SAStex and others.  Associated files will be displayed in Windows Explorer with the SASweave icon. Three operations are provided for associated files:
The file associations are made in the HKEY_CURRENT_USER secti-- user varaibles and system variables.  on of the registry; that is, the associations will only apply to the user who installed SASweave.  This allows users without administrative rights to install SASweave.

How to add Gawk to your Windows PATH

The PATH is a list of directories that Windows uses to search for programs it wants to run.  The location of Gawk must be in this PATH before you can install SASweave.  The instructions given here assume that when you installed Gawk, you specified the installation directory C:\Program Files\GnuWin32.  You need to adapt the instructions if you installed it elsewhere.
  1. From the Start menu, right-click on "My Computer", and select "Properties" from the menu.
  2. Click on the "Advanced" tab in the resulting dialog window.
  3. Click on the button labeled "Environment Variables" near the bottom.
  4. In the User variables list, see if there is an entry for PATH.  
Note that in either case, you add \bin to the installation directory for Gawk.  Click "OK" twice more to exit the dialog windows.

Update information

The NEWS file summarizes the change history of this software.  Look here if you want an older version of the software.

License

Gnu Public License.  See the COPYING for details.