summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/statrep/doc/quickstart.tex
blob: 4cf527ff1c2da958c5b94bfaea1219eed38eee7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
\documentclass{article}
\usepackage{statrep}
\usepackage{parskip,xspace}
\newcommand*{\Statrep}{\mbox{\textsf{StatRep}}\xspace}
\newcommand*{\Code}[1]{\texttt{\textbf{#1}}}
\newcommand*{\cs}[1]{\texttt{\textbf{\textbackslash#1}}}
\setcounter{secnumdepth}{0}
\title{Example and Tutorial for the \Statrep Package}
\author{Tim Arnold and Warren F. Kuhfeld\\SAS Institute Inc., Cary, NC}
\date{April 25, 2012}
\begin{document}
\maketitle
\section{Introduction}
This article provides an example and a
tutorial that show how to use the \Statrep \LaTeX\ package.
For complete details
see the \emph{\Statrep User's Guide} that accompanies the
package (\Code{statrepmanual.pdf}). The package is available
for download at \texttt{http://support.sas.com/StatRepPackage}.

When you use the \Statrep \LaTeX\ package, you use the following
four-step process to create an executable document that
enables you to ensure that your research results are reproducible:
\begin{enumerate}
\item Create your \LaTeX\ document so that it contains your text,
data, and SAS code.

\item Compile your document with pdf\LaTeX\ to generate the SAS
program.

\item Execute the SAS program to capture your output. For each
code block in your document, SAS creates a SAS Output Delivery System (ODS)
document that contains the resulting output.

For each output request in your document, SAS replays the
specified output objects to external files. All your
requested output is generated and captured when you execute
the generated SAS program.

\item Recompile your \LaTeX\ document. In this step, the
requested outputs are embedded in the resulting final PDF document.

You might need to repeat this step so that \LaTeX\ can measure the
listing outputs to ensure that they are framed appropriately.
\end{enumerate}

\section{Step 1: Create Your \LaTeX\ Document}
This article provides you with an example \LaTeX\ document
already created as in step 1.

The purpose of the \Code{Datastep} environment is to read in data.
It produces no output.

The SAS statements in the \Code{Datastep} environment create a new data set
called \Code{Wine}. The \Code{first=} and \Code{last=} options specify that
only a portion of the data set be displayed.

...descriptive text that introduces data...

\begin{Datastep}[first=5, last=3]
data Wine;
   input WineType $ VisitLength @@;
   datalines;
white  80 white  98 white 115 white  89 white 103
white  91 white 119 white  31 white 109 white  95
white  71 white 105 white  66 white 141 white  79
white 113 white  69 white 120 white  87 red    93
red    87 red   106 red    76 red   121 red   143
red    81 red    97 red    74 red   107 red   112
red    67 red   107 red    72 red   116 red    99
red   104 red    91 red   132 red    78 red   107
red   101 red    92
;
\end{Datastep}

The purpose of the \Code{Sascode} environment is to generate output.
The statements in the following \Code{Sascode} environment perform an
analysis that uses the ANOVA procedure (PROC ANOVA).
You use the \Code{store=} option so that
later in your document
you can refer to output that is created in the \Code{Sascode}
environment.
In this example, all output that is generated by the analysis is stored in the ODS document
\Code{wineA}.

...descriptive text that introduces the analysis...

\begin{Sascode}[store=wineA]
ods graphics on;
proc anova data=Wine;
   class WineType;
   model VisitLength = WineType;
run;
ods graphics off;
\end{Sascode}
The \cs{Listing} and \cs{Graphic} tags specify the output to be displayed.
The purpose of the \cs{Listing} tag is to display tabular output and notes.
The purpose of the \cs{Graphic} tag is to display graphical output.

...descriptive text that introduces output...

The \cs{Listing} tag selects three output tables from the \Code{wineA} ODS document:
\Code{ClassLevels}, \Code{NObs}, and \Code{OverallANOVA}

\Listing[store=wineA,
   objects=ClassLevels NObs OverallANOVA,
   caption={Analysis of Variance for Visit Length}]{tsta}

The \cs{Graphic} tag selects the \Code{BoxPlot}
graph from the \Code{wineA} ODS document.

...descriptive text that introduces the graph...

\Graphic[store=wineA,
   objects=BoxPlot,
caption={Box Plots for Visit Length}]{tstb}


\section{Step 2: Compile Your Document}

You can compile your document as follows from the command line:
\begin{verbatim}
   pdflatex quickstart.tex
\end{verbatim}

If you use a \LaTeX-aware editor, such as \TeX works, you can use it to
compile your document.

In either case, when you compile your document, the
\Statrep system produces a PDF file and generates a SAS program.

\textbf{Note:} The requested output is missing after the first compile step.
(This is normal at this step.)

\section{Step 3: Execute the SAS Program}

Open the generated SAS program \Code{quickstart\_SR.sas} in a
SAS session. From the SAS main menu, select
\textsf{Run}$\rightarrow$\textsf{Submit}.

In this step, SAS generates the results that are requested in your document.
By default, tabular output files are created in the `lst' subdirectory and
graphic output files are created in the `png' subdirectory.

\section{Step 4: Recompile Your \LaTeX\ Document}

The last step is to recompile your document with pdf\LaTeX.
As in the first compilation, you can use a \LaTeX-aware editor such
as \TeX works, or you can use the \Code{pdflatex} command in a terminal window.

In this recompilation step, the outputs that are captured by the SAS program
are included in the final PDF document.

\section{Conclusion}

When you generate
the SAS program by compiling your document with pdf\LaTeX,
the \Statrep package does the following:
\begin{itemize}
\item The lines in the \Code{Datastep} environment are passed unchanged to the program.
\item The lines in the \Code{Sascode} environment are parsed for line commands and passed
to the program.
\item Each \cs{Listing} tag  selects the specified notes and tables.

\item Each \cs{Graphic} tag selects the specified graphs.

\end{itemize}

When you execute the generated SAS program, the output that is
specified in the \cs{Listing} and \cs{Graphic}
tags is automatically captured.

When you recompile your \LaTeX\ document, the \cs{Listing} and \cs{Graphic} tags
insert the requested SAS results and page breaks are handled automatically.

\end{document}