The traditional method of including SAS code and corresponding results in a document is to copy and paste them manually. Which is fine if you do it perfectly the first time. But more often than not there is some iteration. You make small adjustments here and there. And all too often you end up with your code and output being out of sync.
When you use the StatRep LaTeX package, you follow a four-step process to create an executable document that guarantees that your code and output are in sync.
- Create a LaTeX file that contains your text and SAS code.
- Compile the LaTeX file to generate two new files.
- A PDF file with placeholders for your output.
- A SAS program containing the code that will generate the output.
- Run the SAS program to generate output.
- Compile the LaTeX file a second time to pull the SAS outputs back into the PDF.
The main advantage of this system is that you don't have to worry about your SAS code and outputs being out of sync. Because the SAS code is embedded within the document, it's definitely going to be the same code that generated your outputs.
You have three options for getting started with StatRep.
- Full blown SAS documentation can be located here.
- Or, a slightly gentler introduction can be found in the SGF paper found here.
- Or, gentlest of all, are the instructions that follow.
- Estimated time to install software, learn syntax, and produce your first output: ~50 minutes.
LaTeX, which is pronounced Lah-tech
or Lay-tech
, is a document preparation system for high-quality typesetting. It is most often used for medium-to-large technical or scientific documents but it can be used for almost any form of publishing. For instance, I've recently used it to write a SESUG paper.
- Install MikTeX (~5 minutes)
- This is a large file. The download will take longer than the install.
- This is the basic LaTeX software for Windows.
- During the install, change the following.
- Preferred paper = Letter
- Install missing packages on-the-fly = Yes
- This allows the software to automatically search for updates and install them without prompting you for permission. This is a good thing.
- Install TexMaker (~5 minutes)
- This is an editor that makes it easier to edit LaTeX documents.
- Watch LaTeX Tutorial 1 (~15 minutes).
- This is a quick way to gain basic familiarity with LaTeX and TexMaker.
StatRep is not software in the traditional sense. It is actually just a collection of files that need to be saved in just the right place and edited in just the right way so that TexMaker and SAS can work together to produce your documents.
There are a lot of little details in what follows. Move slowly.
- Download the StatRep ZIP file by clicking here.
- Initially, just save and extract the contents of the ZIP file to any convenient location.
- Copy the file
statrep_macros.sas
into a directory from which it can be accessed by the SAS Grid.- For instance,
H:/statrep
would be a good choice.
- For instance,
- Locate the directory in which LaTeX was installed.
- Likely here:
C:/Users/<user>/AppData/Roaming/MiKTeX/2.9/tex
- Likely here:
- Under the
tex
folder, create subdirectories forlatex/statrep
.- Thus forming
C:/Users/<user>/AppData/Roaming/MiKTeX/2.9/tex/latex/statrep
- Thus forming
- Copy the following files into this new
statrep
folder.statrep.dtx
statrep.ins
- Open a command prompt, then navigate to the
statrep
folder.- E.g.,
cd C:/Users/<user>/AppData/Roaming/MiKTeX/2.9/tex/latex/statrep
- E.g.,
- Enter the command
pdftex statrep.ins
.- This should have created, at a minimum,
statrep.cfg
.
- This should have created, at a minimum,
- Open
statrep.cfg
in a text editor and edit as follows.- Locate the line
\def\SRmacropath{statrep_macros.sas}
. - Edit to point to where you saved
statrep_macros.sas
.- E.g.,
\def\SRmacropath{H:/statrep/statrep_macros.sas}
- Note: You must use forward slashes (
/
) in the above file path.
- E.g.,
- Locate the line
- Create a
myfirstpaper
folder underH:/statrep
.- Thus creating
H:/statrep/myfirstpaper/quickstart.tex
.
- Thus creating
- Copy
quickstart.tex
(found in thedoc
folder ofstatrep.zip
) into this newmyfirstpaper
folder.- Thus creating
H:/statrep/myfirstpaper/quickstart.tex
.
- Thus creating
- Double-click to open
quickstart.tex
in TexMaker.- In the dropdown at the top of the TexMaker interface (between the blue arrows), make sure the value is set to
PDFLaTeX
.
- In the dropdown at the top of the TexMaker interface (between the blue arrows), make sure the value is set to
- Insert a new line 3 in your LaTeX file that reads
\def\SRrootdir{H:/statrep/myfirstpaper}
.- This line lets
statrep_macros.sas
know where to save your outputs.
- This line lets
- Compile the LaTeX file.
- This should create several files in
H:/statrep/myfirstpaper
.- Examine
quickstart.pdf
. Note the placeholders such asMissing File lst/tsta.lst
. - Examine
quickstart_SR.sas
. Stare in amazement.
- Examine
- This should create several files in
- Run
quickstart_SR.sas
using Enterprise Guide (does not seem to work in batch).- This should generate some folders with output (
lst
,png
). - If the SAS program crashes, see the Gotcha below.
- This should generate some folders with output (
- Compile the LaTeX file a second time.
- This should pull the
lst
andpng
outputs into the PDF file. - Typically you have to compile an extra time to get the image labels to line up right. I do not know why. Just click the button twice and get over it.
- This should pull the
An example LaTeX file, and the PDF that it generates, are included in this repository. The file includes lots of customizations that are useful for SESUG formatting requirements. There are too many customizations to explain them all. Just make yourself a local copy and start editing away. When doing so, be sure to:
- Save the LaTeX file in a separate folder from any other StatRep projects you might be working on.
- E.g.,
H:/SESUG/2017/bestpaperever
- E.g.,
- Modify the 3rd line of the LaTeX file to correspond to this new folder, using forward slashes (
/
) in the folder path.- E.g.,
\def\SRrootdir{H:/SESUG/2017/bestpaperever}
- E.g.,
If the SAS program crashes in step 5 of Use StatRep, the likely cause is that the statrep.cfg
file that you edited in the final step of Install LaTeX components is not the copy of the file that TexMaker is looking at (yes, there are multiple copies of this file created in some installs - this makes no sense). To remedy this problem, search quickstart.log
for the text statrep.cfg
. If the path you see does not match the one you used above, then you will need to repeat the final step of Install LaTeX components (editing \def\SRmacropath{}
) in the copy of statrep.cfg
referenced in quickstart.log
.