/sas-statrep

Streamlined instructions for getting started with the StatRep package.

Primary LanguageTeX

Outline

  1. Overview
  2. Getting Started with LaTeX
  3. Getting Started with StatRep
  4. Example SESUG Paper

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.

  1. Create a LaTeX file that contains your text and SAS code.
  2. Compile the LaTeX file to generate two new files.
    1. A PDF file with placeholders for your output.
    2. A SAS program containing the code that will generate the output.
  3. Run the SAS program to generate output.
  4. 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.

  1. Full blown SAS documentation can be located here.
  2. Or, a slightly gentler introduction can be found in the SGF paper found here.
  3. Or, gentlest of all, are the instructions that follow.
    1. 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.

  1. Install MikTeX (~5 minutes)
    1. This is a large file. The download will take longer than the install.
    2. This is the basic LaTeX software for Windows.
    3. During the install, change the following.
      1. Preferred paper = Letter
      2. Install missing packages on-the-fly = Yes
        1. This allows the software to automatically search for updates and install them without prompting you for permission. This is a good thing.
  2. Install TexMaker (~5 minutes)
    1. This is an editor that makes it easier to edit LaTeX documents.
  3. Watch LaTeX Tutorial 1 (~15 minutes).
    1. 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 components

  1. Download the StatRep ZIP file by clicking here.
    1. Initially, just save and extract the contents of the ZIP file to any convenient location.

Install SAS components (~2 minutes)

  1. Copy the file statrep_macros.sas into a directory from which it can be accessed by the SAS Grid.
    1. For instance, H:/statrep would be a good choice.

Install LaTeX components (~10 minutes)

  1. Locate the directory in which LaTeX was installed.
    1. Likely here: C:/Users/<user>/AppData/Roaming/MiKTeX/2.9/tex
  2. Under the tex folder, create subdirectories for latex/statrep.
    1. Thus forming C:/Users/<user>/AppData/Roaming/MiKTeX/2.9/tex/latex/statrep
  3. Copy the following files into this new statrep folder.
    1. statrep.dtx
    2. statrep.ins
  4. Open a command prompt, then navigate to the statrep folder.
    1. E.g., cd C:/Users/<user>/AppData/Roaming/MiKTeX/2.9/tex/latex/statrep
  5. Enter the command pdftex statrep.ins.
    1. This should have created, at a minimum, statrep.cfg.
  6. Open statrep.cfg in a text editor and edit as follows.
    1. Locate the line \def\SRmacropath{statrep_macros.sas}.
    2. Edit to point to where you saved statrep_macros.sas.
      1. E.g., \def\SRmacropath{H:/statrep/statrep_macros.sas}
      2. Note: You must use forward slashes (/) in the above file path.

Use StatRep (~5 minutes)

  1. Create a myfirstpaper folder under H:/statrep.
    1. Thus creating H:/statrep/myfirstpaper/quickstart.tex.
  2. Copy quickstart.tex (found in the doc folder of statrep.zip) into this new myfirstpaper folder.
    1. Thus creating H:/statrep/myfirstpaper/quickstart.tex.
  3. Double-click to open quickstart.tex in TexMaker.
    1. In the dropdown at the top of the TexMaker interface (between the blue arrows), make sure the value is set to PDFLaTeX.
  4. Insert a new line 3 in your LaTeX file that reads \def\SRrootdir{H:/statrep/myfirstpaper}.
    1. This line lets statrep_macros.sas know where to save your outputs.
  5. Compile the LaTeX file.
    1. This should create several files in H:/statrep/myfirstpaper.
      1. Examine quickstart.pdf. Note the placeholders such as Missing File lst/tsta.lst.
      2. Examine quickstart_SR.sas. Stare in amazement.
  6. Run quickstart_SR.sas using Enterprise Guide (does not seem to work in batch).
    1. This should generate some folders with output (lst, png).
    2. If the SAS program crashes, see the Gotcha below.
  7. Compile the LaTeX file a second time.
    1. This should pull the lst and png outputs into the PDF file.
    2. 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.

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:

  1. Save the LaTeX file in a separate folder from any other StatRep projects you might be working on.
    1. E.g., H:/SESUG/2017/bestpaperever
  2. Modify the 3rd line of the LaTeX file to correspond to this new folder, using forward slashes (/) in the folder path.
    1. E.g., \def\SRrootdir{H:/SESUG/2017/bestpaperever}

Gotcha

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.