summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/statrep/doc/statrepmanual.tex
blob: 723fbb6a5dc730984e7c04ef0ccac8bb6c406756 (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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
\documentclass[article,oneside]{memoir}
\usepackage[T1]{fontenc}
\usepackage{mathptmx,upquote,alltt}
\IfFileExists{helvet.sty}{\usepackage[scaled=0.92]{helvet}}{\relax}
\IfFileExists{couriers.sty}{\usepackage[scaled=0.95]{couriers}}{\relax}
\usepackage{float,graphicx,xspace,framed,xcolor}
\definecolor{shadecolor}{rgb}{0.97,0.97,0.97}
\definecolor{lightblue}{rgb}{0.93,0.95,1.0}
\definecolor{darkblue}{rgb}{0,0,0.6}
\definecolor{darkred}{rgb}{0.6,0,0}
\setlength{\parindent}{0pt}
\nonzeroparskip
\usepackage[
   bookmarks=true,
   hyperindex = true,
   pdfpagemode = useoutlines,
   pdfpagelabels = true,
   plainpages = false,
   colorlinks = true,
   linkcolor=darkblue,
   filecolor=darkblue,
   citecolor=darkblue,
   urlcolor=darkblue,
]{hyperref}
\usepackage{attachfile}
\usepackage{memhfixc}
\raggedbottom
\hyphenation{StatRep}
\chapterstyle{article}
\DeclareTextFontCommand{\Code}{\ttfamily}
\newcommand*{\StatRep}{\textsf{StatRep}\xspace}
\newcolumntype{P}[1]{>{\raggedright\arraybackslash}p{#1}}
\setlength{\FrameSep}{1pt}
\title{The \StatRep System for Reproducible Research}
\author{Tim Arnold and Warren F. Kuhfeld\\SAS Institute Inc.}
\makeindex
\begin{document}
\maketitle
\tableofcontents*%\listoftables\listoffigures
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\part{User's Guide}
\chapter{Synopsis}
The \StatRep system consists of a \LaTeX\ package and a suite of SAS macros that
support SAS users who want to create documents with reproducible results.

The \LaTeX\ package provides two environments and
two tags that work together to display your SAS code and results and to
generate the SAS program that produces those results. The two environments
(\Code{Datastep} and \Code{Sascode}) display SAS code.
The two tags (\cs{Listing} and \cs{Graphic}) display SAS output.

The generated SAS program includes calls to the \StatRep macros that use the SAS
Output Delivery System (ODS) document to capture the output as external files.
These SAS macros are included in the package file \Code{statrep\_macros.sas}.

The \StatRep package is available at \url{http://support.sas.com/StatRepPackage}

By default, \StatRep displays SAS output tables as generated by the ODS Listing
destination; that is, the output tables are displayed as plain text. However, you can
specify that \StatRep display \LaTeX\ outputs, generated by SAS, instead
(see appendix \ref{latexoutput} for details).

You can use \StatRep with a standalone SAS installation on your PC, or you can use it
in conjunction with \textbf{SAS Studio} and \textbf{SAS University Edition}
(see appendix \ref{sasstudio} for details).

Bundled with the \StatRep package is the \Code{longfigure} package for
multipage figures.
You can use the \Code{lonfigure} package in other \LaTeX\ documents.

The \StatRep system was designed to be flexible enough to support serious publishing systems.
It can handle many different situations and it is very customizable.
This document
covers all aspects of \StatRep; however, for most users, the \textit{User's Guide} portion
will suffice. For those who need more advanced techniques and customization, please see the
\textit{Reference Manual}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Introduction}

At the end of a research project, one of the most difficult tasks remains: documentation.
The task is especially difficult with computational research because you
must ensure that the displayed program code works as expected and exactly produces the
displayed output.

The \StatRep package, a single-source document system,
is an open-source software project that you can use for your own research documentation
to ensure that the results you display can easily be reproduced by your readers.
The \StatRep package is based on the \LaTeX\ typesetting system. You write your paper using
both the usual \LaTeX\ markup and the customizations and SAS macros that this package provides.
The system reads the code and markup from the single source (your document) and creates a
SAS program. This automatically generated SAS program produces the results that are displayed
in your document.

Comparable projects such as Sweave (Leisch 2002) and SASweave  (Lenth 2007)
address the problem of reproducibility through the use of a special intermediate language.
Although similar in spirit to those systems, \StatRep differs in that it is a
normal \LaTeX\ package; no special steps are needed to create the \LaTeX\
file or the SAS program.   In addition, \StatRep provides both a complete, customizable system for
automatic handling of multiple outputs and page breaking and an easy-to-use,
flexible method for output selection.

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

\item Compile the document with pdf\LaTeX. You can use a LaTeX-aware
      editor such as \TeX works, or you can use the command-line command \Code{pdflatex}.
      This step generates the SAS program that is needed to produce the results.
      If the name of your document is \textit{myarticle.tex}, the name of the generated SAS
      program is \textit{myarticle\_SR.sas} by default.

\item Execute the SAS program to capture your output.

During execution of the SAS program, for each code block in your document,
SAS creates a SAS Output Delivery System (ODS) document that contains the resulting output.
For more information about ODS documents, see the
\textit{SAS Output Delivery System User's Guide}.
For each output request (the included \cs{Listing} and \cs{Graphic} tags) in your document, SAS replays the specified output objects
to external files. All of your requested output is generated and captured when you
execute the generated SAS program.

\item Recompile the document with pdfLaTeX. This step compiles your
      document to PDF, this time including the SAS results
      that are generated in the preceding step.

      In some cases listing outputs may not be framed properly after this step.
      If your listing outputs are not framed properly, repeat this step so that
      LaTeX can remeasure the listing outputs.

\end{enumerate}

When you need to make a change in your data or SAS code, you make the change in
one place (the \LaTeX\ source file) and repeat steps 2 through 4.
Your changes are automatically displayed in your code and in your results.
You perform the steps only as needed---when you change your data or code.

You can share your \LaTeX\ source with colleagues and be sure that your results
are reproducible. Any SAS user can reproduce your analysis with your \LaTeX\ document
and the supplemental files that are described in this manual.

\section{Requirements for the \StatRep Package}
\index{package!requirements}
To use the \StatRep package, you need SAS 9.2 or later,
the \LaTeX\ typesetting system
(the  pdf\LaTeX\ typesetting engine must be version 1.30 or later), and the \StatRep package itself.

For complete step-by-step instructions for installation, see appendix \ref{install}.

\section{Package Usage}
\index{package!usage}
  To use the \StatRep package, include it in your document preamble after you
  declare the \Code{documentclass}.
  Figure \ref{fig:usage} displays an example of how you can use the \StatRep package.

\begin{figure}[H]
\begin{shaded}
\begin{verbatim}
\documentclass{book}
\usepackage[figname=output,resetby=chapter]{statrep}
\end{verbatim}%
\end{shaded}
\caption{Example of Using the \StatRep Package}\label{fig:usage}
\end{figure}

 The \StatRep package supports the following options:\index{package!options}
     \begin{itemize}
     \item \Code{color} specifies color support for SAS output tables.
     This option is only used in conjunction with
     the ODS LaTeX tagset (see appendix \ref{latexoutput}).

     \item \Code{generate} specifies whether a SAS program
     is generated at compile time. \index{generate option}
     It can have a value of \Code{true} or \Code{false}; the default is \Code{true}.

     \item \Code{figname=} specifies the name of a \LaTeX\ counter
     that is used for numbering outputs\index{figname option}.
     The default is \Code{figure}. If you specify a value for the \Code{figname}
     option for which no counter exists,
     a counter is created.\index{figure names}\index{figname option}

     \item \Code{resetby=} specifies that the counter for output numbering be reset with
     each change in the specified counter value. For example, if \Code{resetby=chapter},
     all output numbering is reset when the chapter value changes.\index{resetby= option}
     \end{itemize}

     The options \Code{figname=} and \Code{resetby=} are not used directly by the \StatRep
     package but are passed to the \Code{longfigure} package, which
     is provided with the \StatRep package.
    The \Code{longfigure} package
    supports display and page breaking within a stream of outputs, and it can be
    used independently of the \StatRep package. See chapter{longfigure} for
more information.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Getting Started}\label{gs}

This section provides a simple example of how you can use the \StatRep package
to produce a document with reproducible results.
You can follow along with the actual code: extract this
\textattachfile[color=0 0 0.6]{example.tex}{example \LaTeX\ file} that
contains the code in this section if your PDF viewer supports file annotations.

  Two code environments
  (\Code{Datastep}, shown in Figure \ref{fig:d1}, and
  \Code{Sascode}, shown in Figure \ref{fig:s1})
  and two output tags
  (\cs{Listing} and \cs{Graphic}, shown in Figure \ref{fig:slg})
  are used to generate a SAS program that produces
  the necessary output files.

  The code from the \Code{Datastep} environment is passed unchanged to the
  generated SAS program.\index{Datastep environment}
\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
\begin{Datastep}
proc format;
   value $sex 'F' = 'Female' 'M' = 'Male';
data one;
   set sashelp.class;
   format sex $sex.;
run;
\end{Datastep}
\end{verbatim}
\end{snugshade}
\caption{Example of \texttt{Datastep} Environment}\label{fig:d1}
\end{figure}

  The code in the \Code{Sascode} environment is parsed by the \StatRep package before it is
  written to the generated SAS program.\index{Sascode environment}

\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
\begin{Sascode}[store=class]
proc reg;
    model weight = height age;
run;
\end{Sascode}
\end{verbatim}
\end{snugshade}
\caption{Example of \texttt{Sascode} Environment}\label{fig:s1}
\end{figure}

  The \cs{Listing} and \cs{Graphic} tags convey information to \LaTeX\ and to SAS.
  The tags specify the names of the output files to insert into the document
  and the captions for the output.
  Additionally, the tags specify the names of the output files to
  create and they can specify which
  ODS objects to capture. In this example, no objects are specified so all
  objects are captured.
  \index{Listing tag}\index{Graphic tag}%

\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
\Listing[store=class,
         caption={Regression Analysis}]{rega}

\Graphic[store=class, scale=0.9,
         caption={Graphs for Regression Analysis}]{regb}
\end{verbatim}
\end{snugshade}
\caption{Example of \texttt{Listing} and \texttt{Graphic} Tags}\label{fig:slg}
\end{figure}

  Figure \ref{fig:sgp} shows the SAS code that is generated
  from the preceding \LaTeX\ source when you compile the document.

\begin{figure}[H]
\begin{framed}
\begin{snugshade}
{\hfil\emph{generated from }\textbf{Datastep Block}\hfil}
\begin{verbatim}
proc format;
   value $sex 'F' = 'Female' 'M' = 'Male';
data one;
   set sashelp.class;
   format sex $sex.;
run;
\end{verbatim}
\end{snugshade}
\begin{snugshade}
{\hfil\emph{generated from }\textbf{Sascode Block}\hfil}
\begin{verbatim}
%output(class)
proc reg;
    model weight = height age;
run;
%endoutput(class)
\end{verbatim}
\end{snugshade}
\begin{snugshade}
{\hfil\emph{generated from }\textbf{Listing \& Graphic Tags}\hfil}
\begin{verbatim}
%write(rega,store=class,type=listing)

%write(regb,store=class,type=graphic)
\end{verbatim}
\end{snugshade}
\end{framed}
\caption{Generated SAS Code}\label{fig:sgp}
\end{figure}

  When you generate the SAS program by compiling your \LaTeX\ document,
  the lines in the \Code{Datastep} environment are passed unchanged to the program
  and
  the lines in the \Code{Sascode}
  environment are wrapped between two SAS macros (\Code{\%output} and \Code{\%endoutput}),
  whose definitions accompany this package (\texttt{statrep\_macros.sas}).
  \index{statrep\_macros.sas}\index{SAS macros!output}\index{SAS macros!endoutput}
  The macros and their options are discussed in detail in section \ref{macros}.

  The \cs{Listing} tag results in a call to the \Code{\%write} macro that selects all notes and tables from the ODS document.\index{SAS macros!write}
  The \cs{Graphic} tag results in a call to the \Code{\%write} macro that selects all graphs from the ODS document.

  When you execute the generated SAS program that is displayed
  in Figure \ref{fig:sgp}, the SAS results created in the \Code{Sascode} block are contained
  in the ODS document \Code{class}. The \Code{\%write} macro writes the requested results from the ODS document
  to the specified
  external files.

  When you compile your \LaTeX\ document again, the \cs{Listing} and \cs{Graphic} tags
  insert the requested SAS results, handling page breaks automatically.

  The first listing in the example document is shown in Figure \ref{exfig}.
\definecolor{shadecolor}{rgb}{0.93,0.95,1.0}

\begin{figure}[H]
\caption{Example listing output}\label{exfig}
\begin{snugshade}
\centering
\includegraphics[width=0.8\textwidth]{images/example_output}
\end{snugshade}
\end{figure}

\definecolor{shadecolor}{rgb}{0.97,0.97,0.97}

By default, \StatRep generates listing output from the
SAS ODS Listing destination. The preceding figure provides an example
of how the SAS output is displayed in your LaTeX document.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Syntax}

     The \StatRep package provides two environments and two tags that work
     together to display your SAS code and results and generate the SAS program
     that produces those results.

     The environments:
     \begin{itemize}
     \item The \Code{Datastep} environment contains SAS code blocks that produce no output.
     Its purpose is to read in data.
     \item The \Code{Sascode} environment contains SAS code that generates output to be
     captured. It supports line-based commands to identify
     code lines that should only be displayed, only passed to the generated program,
     or both displayed and passed to the generated program.
     \end{itemize}

     The tags:
     \begin{itemize}
     \item The \cs{Listing} tag provides information to the generated program about
     which tabular SAS output should be captured.
     It also provides information to \LaTeX\  about how that output should be displayed.
     \item The \cs{Graphic} tag provides information to the generated program about
     which graphical SAS output should be captured.
     It also provides information to \LaTeX\ about how that output should be displayed.
     \end{itemize}

     The environments and tags are described in detail in the following sections.

\section{Code Environments}

\subsection{Datastep Environment}\index{Datastep environment}

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

  The \Code{Datastep} contents are passed unchanged to the generated program.
  The \Code{Datastep} block is indented by three spaces in the PDF file.
  You can adjust the amount that the block is indented; see
  section \ref{custom} for details. The block indent is provided automatically so that
  your data and program lines can begin in the first column in your \LaTeX\ source.

  Because you begin the \Code{Datastep} data lines in the
  first column, formatted or column input statements will work correctly when
  pasted into a SAS session.\index{copy and paste}\index{interactive SAS session}


  Although the purpose of the \Code{Datastep} environment is to read in data,
  \index{reading data}%
  it can contain any SAS code that does not generate output
  to be captured.  Additional statements typically include
  TITLE and OPTIONS statements and PROC FORMAT steps. See Figure \ref{fig:sd2}
  on page \pageref{fig:sd2} for an example.


Table \ref{dsopt} summarizes the \Code{Datastep} environment options.
\index{Datastep environment!options}
\index{program option}\index{display option}\index{first= option}\index{last= option}%
\index{fontsize= option}

\begin{table}[H]
\caption{Commonly Used \Code{Datastep} Environment Options}\label{dsopt}
\begin{tabular}{lP{3.75in}}
\hline
\textbf{Option}  &  \textbf{Action} \\
\hline
                    & By default, all lines are displayed and written to the program.
\\[0.5\baselineskip]
\Code{program}      &
                 Specifies that all lines in the environment
                 be written to the generated program only
                (that is, no lines are displayed). This option is useful when you need
                to produce a data set that is not central to the topic being
                discussed and does not need to be displayed.
\\[0.5\baselineskip]
\Code{display}      &
                Specifies that all lines in the environment be displayed
                only (that is, no lines are written to the program). This option is
                useful when you need to show code fragments that will not run as is or
                example code that is not needed
                for later output generation. A \Code{Datastep} environment that specifies
                the \Code{display} option is similar to a plain \Code{verbatim} environment except
                that it is automatically indented when displayed.
\\[0.5\baselineskip]
\Code{first=\textit{n}} &
               Specifies that the first \textit{n} lines
               in the environment be displayed. The option affects only the displayed
               code block.
               This option is useful when you have many data lines that do not need to be
               displayed, but that must be available to the program.
               After the \textit{n}th line is displayed, the following
               text line is written in the displayed code block:
               \par\texttt{... more data lines ...}\par%
               You can specify different text to be used;
               see section \ref{custom} for details.
\\[0.5\baselineskip]
\Code{last=\textit{m}} &
               Specifies that the last \textit{m} lines
               in the environment be displayed. The option affects only the displayed
               code block.
               This option is used in conjunction with the \Code{first=} option to show
               the ending lines of the \Code{Datastep} environment. Without the \Code{first=}
               option, the \Code{last=} option has no effect.
\\[0.5\baselineskip]
\Code{fontsize=}   & Specifies the \LaTeX\ font size used to display the
       code block. For exampe, \Code{fontsize=small} or \Code{fontsize=footnotesize}.
\\
\hline

\end{tabular}
\end{table}

See the section \titleref{dsex} for an example.

  \subsection{Sascode Environment}\index{Sascode environment}

The purpose of the \Code{Sascode} environment is to generate output.
In addition to the environment options, it supports
line commands that enable you to specify certain lines as display-only or program-only.

 The \Code{Sascode} environment is parsed for line commands, and the appropriate lines are
 passed to the program and displayed. The displayed code block is indented by three spaces.
  You can adjust the amount the block should be indented; see section \ref{custom} for
  details.\index{display option} The block indent is provided
  automatically so that your program lines can begin in the first column in your \LaTeX\ source.

  Because all line commands are valid SAS statements,
  you can copy \Code{Sascode} blocks and paste them directly
  into a SAS session.\index{copy and paste}\index{interactive SAS session}

Table \ref{scopt} summarizes the \Code{Sascode} environment options.
\index{Sascode environment!options}\index{store= option}\index{program option}%
\index{display option}\index{fontsize= option}%

\begin{table}[H]
\caption{Commonly Used \Code{Sascode} Environment Options}\label{scopt}
\begin{tabular}{lP{3.75in}}
\hline
\textbf{Option}  &  \textbf{Action} \\
\hline
& By default, all lines are displayed and written to the program. \\[0.5\baselineskip]
\Code{store=}      &
         Specifies the name of the ODS document to contain the SAS output.
\\[0.5\baselineskip]

\Code{program}     & Specifies that  all lines in the environment
                     be written to the program only
                (that is, no lines are displayed). This option is useful when you need
                to execute code that is not central to the topic being discussed and need not
                be displayed.
\\[0.5\baselineskip]
\Code{display}     &
                  Specifies that all lines in the environment
                  be displayed only (that is, no lines are written to the program).
                This option is
                useful when you need to show example code
                fragments that will not run as is or that are not needed
                for later output generation. A \Code{Sascode} environment that specifies
                the \Code{display} option is similar to a plain \Code{verbatim} environment except
                that it is automatically indented when displayed.
\\[0.5\baselineskip]
\Code{fontsize=}   &
        specifies the \LaTeX\ font size used to display the
       code block (for example, \Code{fontsize=small} or \Code{fontsize=footnotesize}).
\\
\hline
\end{tabular}
\end{table}

The \Code{Sascode} environment also supports
a finer degree of control with line-based commands to identify lines that should
be only displayed or only passed to the generated program.

Table \ref{lcmd} summarizes the line commands you can use in the \Code{Sascode} environment.
\index{Sascode environment!line commands}
\index{program line command}\index{display line command}

\begin{table}[H]
\caption{\Code{Sascode} Line Commands}\label{lcmd}
\begin{tabular}{lP{3.5in}}
\hline
\textbf{Option}  &  \textbf{Action} \\
\hline
 \Code{\%* program} \textit{n} \Code{;} & The next \textit{n} lines are only written to
                                          the program and not displayed.\\[0.5\baselineskip]
 \Code{\%* display} \textit{n} \Code{;} & The next \textit{n} lines are only displayed
                                          and not written to the program.\\[0.5\baselineskip]
 \Code{\%*;} \textit{code line}  & The current line is only written to the
                                      program and not displayed.\\
\hline
\end{tabular}
\end{table}

  The \Code{Sascode} environment is parsed for line commands before being written
  to the generated program file.

See the sections \titleref{scex} and \titleref{scexlc} for examples.


  By using a combination of environment options and line commands, you have
  complete control over the displayed code and the generated program contents.

\section{Outputs}
     \index{SAS ODS outputs}\index{Listing tag}\index{Graphic tag}
The \cs{Listing} and \cs{Graphic} tags specify the outputs 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.

     All figures are centered. If the figure width is narrower than the text block, the
     figure is centered with respect to the text block. Otherwise, the figure is
     centered with respect to the page.

     The \cs{Listing} and \cs{Graphic} tags support a set of options and have one
     mandatory argument, which specifies the filename prefix for the output
     to be generated and displayed.
     The prefix must be unique; otherwise the output from one example will
     overwrite another.

     Furthermore, the prefix must not end in a numeral so that the prefix name does not interfere
     with SAS-generated output file names.
    When SAS generates a set of files from one ODS selection, it follows a
    pattern: the first file that is generated is identical to the filename, the next
    file that is generated has the same name with a ``1'' appended to it, the next file
    has the same name with a ``2'' appended, and so on.

     The options supported by the \cs{Listing} and \cs{Graphic} tags are used by
     the \StatRep \LaTeX\ package and by the \StatRep SAS macros.

     The following table lists all options. Subsequent tables provide descriptions
     for each option and how it is used in LaTeX and in SAS.
\begin{table}[H]
\caption{Master List of Output Tag Options}
     \begin{tabular}{lll}
     \toprule
     \textbf{Option Name} & \textbf{Used by} & \textbf{Output Tag}\\
     \midrule
\Code{caption=}    &  LaTeX        & Listing, Graphic \\
\Code{dest=}       &  LaTeX, SAS   & Listing \\
\Code{dpi=}        &  SAS          & Graphic \\
\Code{firstobj=}   &  SAS          & Listing, Graphic \\
\Code{fontsize=}   &  LaTeX        & Listing (ODS Listing destination) \\
\Code{height=}     &  SAS          & Graphic \\
\Code{lastobj=}    &  SAS          & Listing, Graphic \\
\Code{linesize=}   &  LaTeX, SAS   & Listing (ODS Listing destination) \\
\Code{objects=}    &  SAS          & Listing, Graphic \\
\Code{options=}    &  SAS          & Listing, Graphic \\
\Code{pagesize=}   &  SAS          & Listing \\
\Code{pattern=}    &  SAS          & Listing, Graphic \\
\Code{scale=}      &  LaTeX        & Graphic \\
\Code{store=}      &  LaTeX, SAS   & Listing, Graphic \\
\Code{style=}      &  SAS          & Listing (ODS LaTeX destination), Graphic \\
\Code{type=}       &  SAS          & Listing, Graphic \\
\Code{width=}      &  LaTeX, SAS   & Graphic \\
\bottomrule
\end{tabular}
\end{table}

     \subsection{Options Used by the \textsf{StatRep} \LaTeX\ Package}
     \index{Listing tag!options}\index{Graphic tag!options}
  The following options are used by the \StatRep \LaTeX\ package.
  \index{caption= option}\index{fontsize= option}\index{linesize= option}%
  \index{scale= option}\index{store= option}\index{width= option}

  \begin{description}
     \item[\Code{caption=}] specifies the caption to use for an output.

     \item[\Code{dest=}] specifies the ODS destination to use for generating the output.
     The default value is \Code{listing}. The other possible value is \Code{latex}, which
     specifies that Listing output be generated and displayed as LaTeX tables.

     \item[\Code{fontsize=}] specifies the \LaTeX\ font size to use to display an output
    (for example, \Code{fontsize=small} or \Code{fontsize=footnotesize}).

     \item[\Code{linesize=}] specifies the line size used to generate and display
     \Code{Listing} output. By default, the value is 80 columns.
     This specification lasts for the duration of this step. The current line size is
     restored at the end.
     Typical values are \Code{80}, \Code{96}, or \Code{120}.

     For extremely wide output tables, you can use the \Code{linesize} and \Code{fontsize}
     options together (for example, \Code{linesize=120} and \Code{fontsize=scriptsize}).
     The \Code{linesize} option affects how SAS captures the table. The \Code{fontsize}
     option specifies how \LaTeX\ displays the table.\index{linesize= option}%
     \index{fontsize= option}\index{wide output}

     \item[\Code{scale=}] specifies a factor by which to scale a \Code{Graphic} image.
     For example, specify \Code{scale=0.5} to scale the image to half its original size,
     or specify \Code{scale=2} to scale it to double its original size.

    \item[\Code{store=}] specifies the name of the ODS document that is created in a
     \Code{Sascode} environment. When you specify the \Code{store=} option,
     the \StatRep package adds the appropriate SAS macro calls to the
     generated program.

     \item[width=] specifies the width to generate and display \Code{Graphic} output
           The default is 6.4 inches, which is the standard width for ODS graphs.

  \end{description}

  \subsection{Options Passed to the  \textsf{StatRep} SAS Macros}\label{sasopts}
  \index{SAS macro options}
The \Code{store=}, \Code{linesize=}, and \Code{width=} options described in the previous
section are passed to the \StatRep SAS macros.
\index{dpi= option}\index{firstobj= option}\index{height= option}\index{lastobj= option}
\index{linesize= option}\index{objects= option}\index{options= option}
In addition, the following options are passed to the \StatRep SAS macros:
  \begin{description}

  \item[\Code{dest=}] specifies the ODS destination to use for generating the output.
     The default value is \Code{listing}. The other possible value is \Code{latex}, which
     specifies that Listing output be generated and displayed as LaTeX tables.

    \item[\Code{dpi=}] specifies dots per inch (DPI) to use in generating graphs.
  The default is \Code{dpi=300}. A typical alternative is \Code{dpi=100}.

  \item[\Code{firstobj=}] specifies the first data object to capture in an output stream.
  All objects after and including the specified object
  are displayed, up to the final object
 (or optionally up to the object specified in \Code{lastobj=}).
  You can use \Code{options=skipfirst} to begin with the object after the one specified in \Code{firstobj=}.
  See section \ref{selection} for details.

  \item[\Code{height=}] specifies the height of graphs. The default is 0.75 times the width.

  \item[\Code{lastobj=}] specifies the last data object to capture in an output stream.
  All objects starting with the first object
  (or optionally the object specified in \Code{firstobj=}) are displayed up to and
  including the specified object.
  You can use \Code{options=skiplast} to end with the object before the one specified in \Code{lastobj=}.

\item[\Code{linesize=}] specifies the line size used to generate and display
     \Code{Listing} output. By default, the value is 80 columns.
     This specification lasts for the duration of this step. The current line size is
     restored at the end.
     Typical values are \Code{80}, \Code{96}, or \Code{120}.

  \item[\Code{objects=}] specifies a space-separated list of ODS objects to capture
  in an output stream.
  The names that are used for selection come from the ODS document.
  If you specify \Code{objects=}, then you can also specify object breaking rules
  (where page breaks can occur). See section \ref{selection} for details.

  \item[\Code{options=}] specifies binary options.  Specify one value or a space-separated
  list of values (for example, \Code{options=skipfirst skiplast}).
  You can specify the following values (the default is \Code{options=autopage}):

  \begin{description}
  \item[\Code{autopage}] specifies that the first \cs{Listing}
  command or \Code{\%write} macro start a new output stream with
  titles, procedure titles, and so on.
  Page breaks also occur at other places where the procedure
  explicitly sets a page break. The \Code{autopage} value is the default.
  See also the \Code{nopage} and \Code{newpage} values.
  \index{autopage option}

 \item[\Code{graph}] specifies that only graphs be selected.
  You can alternatively specify \Code{type=graph}.\index{graph option}

  \item[\Code{list}] specifies that the contents of the ODS document be listed
  in the SAS log. This value does not run PROC DOCUMENT to replay the output.\index{list option}

  \item[\Code{newpage}] specifies that SAS force a new page for the first object.
  \index{newpage option}

  \item[\Code{nopage}] suppresses page breaks.\index{nopage option}

  \item[\Code{onebox}] groups all tables, notes, reports, and so on into a
  single piece of SAS output. You cannot specify this option to group graphs.
  See section \ref{selection} for more information about grouping.\index{onebox option}

  \item[\Code{skipfirst}] modifies the \Code{firstobj=} option so that the first object in the
  list is not selected. This enables you to select all objects after the one
  specified in \Code{firstobj=}.\index{skipfirst option}

  \item[\Code{skiplast}] modifies the \Code{lastobj=} option so that the last object
  in the list is not selected. This enables you to select all objects before
  the one specified in \Code{lastobj=}.\label{skiplast}\index{skiplast option}

  \item[\Code{table}] selects all objects
  (tables, notes, reports, and so on) except graphs. You can
  alternatively specify \Code{type=listing}.\index{table option}

  \end{description}

  \item[\Code{pagesize=}] specifies the page size. The default is the page size currently in effect.
  This specification lasts for the
  duration of this step. The current page size is restored at the end.\index{pagesize= option}

  If you have not changed the page size, the default page size set by the \StatRep
  package is 500. This large page size is the default so that output is generated with
  minimal new pages caused by page boundaries. For large tables, you can specify a smaller
  page size to force more page breaks. See section \ref{custom} for information about
  how to change the \StatRep default. See section \ref{large} for information about how
  to use the \Code{pagesize=} option with large tables.

  \item[\Code{pattern=}] provides an optional and additional selection criterion.
  Specify part of a path (for example, a group name).\index{pattern= option}
  Only objects whose name includes the specified value are selected.

    \item[\Code{store=}] specifies the name of the ODS document that is created in a
     \Code{Sascode} environment. When you specify the \Code{store=} option,
     the \StatRep package adds the appropriate SAS macro calls to the
     generated program.\index{store= option}

  \item[\Code{style=}] specifies the ODS style to use in generating output.
    The default is \mbox{\Code{style=Statistical}}. You can change the default style
    (for example, to \Code{HTMLBlue}) by inserting the following line into a \Code{Sascode}
    or \Code{Datastep} environment:\index{style= option}

\begin{snugshade}
\begin{verbatim}
 *; %let defaultstyle=HTMLBlue;
\end{verbatim}
\end{snugshade}

    This option affects ODS graphs only when used in a \cs{Graphic} tag.
    You can specify this option in the \Code{\%output} macro to set the style
    for GRSEG graphs (graphs that are produced by legacy SAS/GRAPH
    procedures such as the GPLOT, GMAP, and GCHART procedures).
    GRSEG graphs are stored in catalogs
    and cannot be changed after they are generated. In contrast,
    style, DPI, and so on for ODS graphis can be changed after the graph is initially created.
    See section \ref{grseg} for more information.

 \item[\Code{type=\emph{listing}|\emph{graph}}] specifies that only listings or
  only graphs be selected.
  You can alternatively specify \Code{options=table} or \Code{options=graph}.
      \item[\Code{width=}] specifies the width to generate and display \Code{Graphic} output
           The default is 6.4 inches, which is the standard width for ODS graphs.

  \end{description}

\chapter{Examples}
\section{Using the Datastep Environment}\label{dsex}
\index{Datastep environment}
  Figure \ref{fig:sd2} displays an example \Code{Datastep} environment. The left margin for
  the environment is in the first column, which is where the data lines themselves begin.
  This ensures that the variables will be read correctly.

\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
\begin{Datastep}[first=9, last=3]
title 'Probit Analysis, Newspaper Survey';
proc format;
   value subscrib 1 = 'accept' 0 = 'reject';
run;
data news;
   input sex $ 1-6 age 12-13 subs 18 ;
   datalines;
Female     35    0
Male       45    1
Female     51    0
Male       54    1
Female     35    0
Female     48    0
Male       46    1
Female     46    1
Male       38    1
Male       49    1
Male       50    1
Female     47    0
Female     39    0
Female     45    0
Male       39    1
Female     39    0
Female     52    1
Male       58    1
Female     32    0
Female     35    0
;
\end{Datastep}
\end{verbatim}
\end{snugshade}
\caption{\texttt{Datastep} Environment with Options}\label{fig:sd2}
\end{figure}

  In Figure \ref{fig:sd2}, the options to the \Code{Datastep} environment specify that only a portion
  of the code block be displayed.  All lines in the environment are written to the
  generated program.

  The option \Code{first=9} specifies that the displayed code
  block contain the TITLE, the PROC FORMAT code, and the DATA step block through the
  second line of data (the first nine input lines). After these lines, the
  following text is displayed:\par\texttt{... more data lines ...}

  The option \Code{last=3} specifies that the displayed code block
  will contain the last three lines of the environment.

  Figure \ref{fig:sd3} shows the display resulting from the preceding
\Code{Datastep} environment.
\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
   title 'Probit Analysis, Newspaper Survey';
   proc format;
      value subscrib 1 = 'accept' 0 = 'reject';
   run;
   data news;
      input sex $ 1-6 age 12-13 subs 18 ;
      datalines;
   Female     35    0
   Male       45    1

      ... more data lines ...

   Female     32    0
   Female     35    0
   ;
\end{verbatim}
\end{snugshade}
\caption{Displayed \texttt{Datastep} Environment with Options}\label{fig:sd3}
\end{figure}


\section{Using the Sascode Environment}\label{scex}\index{Sascode environment}
Figure \ref{sb} displays an example \Code{Sascode} environment.

\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
\begin{Sascode}[store=mdoc]
proc reg data=h38 plots=predictions(X=Year);
   model Population = Year Yearsq;
quit;
\end{Sascode}
\end{verbatim}
\end{snugshade}
\caption{Sascode Block}\label{sb}
\end{figure}
  The code displayed in Figure \ref{sb} contains SAS code that
performs a regression analysis. Because no line commands are given,
the code block is written as-is to the generated SAS program, as shown
in Figure \ref{figsb}.
\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
%output(mdoc);
proc reg data=h38 plots=predictions(X=Year);
   model Population = Year Yearsq;
quit;
%endoutput(mdoc);
\end{verbatim}
\end{snugshade}
\caption{Generated Code from Sascode Block }\label{figsb}
\end{figure}

\section{Using the Sascode Environment with Line Commands}\label{scexlc}
\index{Sascode environment!line commands}
Figure \ref{sblc} displays an example
  \Code{Sascode} environment that contains line commands.

\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
\begin{Sascode}[store=mdoc]
 * program  2;
libname mylib 'c:/mylibs';
filename in1 'h38.ssp';
 * display 2;
libname mylib 'path to your library directory';
filename in1 'path to data directory/h38.ssp';
proc reg data=mylib.h38 plots=predictions(X=Year);
   model Population = Year Yearsq;
quit;
\end{Sascode}
\end{verbatim}
\end{snugshade}
\caption{Sascode Block with Line Commands}\label{sblc}
\end{figure}
  The code displayed in Figure \ref{sblc} contains
  two line commands that delineate two
  specifications for the \Code{libname} and \Code{filename} SAS statements.
  The line command \Code{\mbox{\%* program 2;}} specifies that the location-specific
  definitions be passed to the generated program,
   as shown in Figure \ref{fig:gsblc}.
\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
 output(mdoc);
libname mylib 'c:/mylibs';
filename in1 'h38.ssp';
proc reg data=mylib.h38 plots=predictions(X=Year);
   model Population = Year Yearsq;
quit;
 endoutput(mdoc);
\end{verbatim}
\end{snugshade}
\caption{Generated Code from Sascode Block with Line Commands}\label{fig:gsblc}
\end{figure}

  The line command \Code{\%* display 2;} in Figure \ref{sblc}
  specifies that the generic version
  of the \Code{libname} and \Code{filename} statements be displayed,
  as shown in Figure \ref{dsblc}.
\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
   libname mylib 'path to your library directory';
   filename in1 'path to data directory/h38.ssp';
   proc reg data=mylib.h38 plots=predictions(X=Year);
      model Population = Year Yearsq;
   quit;
\end{verbatim}
\end{snugshade}
\caption{Displayed Code from Sascode Block with Line Commands}\label{dsblc}
\end{figure}

\section{Selecting ODS Objects by Default}\label{odsdefault}
\index{ODS object selection}

  When you use the \cs{Graphic} tag, all graph objects are automatically selected.
  When you use the \cs{Listing} tag, all non-graph objects such as tables and notes
  are automatically selected.  When you use the \Code{\%write} macro, you can specify
  the \Code{options=graph} option to select graphs or the \Code{options=table} to
  select tables and notes.

  The following statements select all of the tables for the \cs{Listing}
  display and all of the graphs for the \cs{Graphic} display:

\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
\begin{Sascode}[store=docgs1]
ods graphics on;
proc corresp data=PhD short;
   var y1973-y1978;
   id Science;
run;
\end{Sascode}

\Listing[store=docgs1,
   caption={Inertia and Chi-Square Decomposition}]{crsi1a}

\Graphic[store=docgs1,
   caption={Correspondence Analysis of Ph.D. Data}]{crsi1b}
\end{verbatim}
\end{snugshade}
\caption{Object Selection with the \cs{Listing} and \cs{Graphic} Tags}\label{optionoption}
\end{figure}

  The log information tables display the selected objects for each
  block of output.

  The first information table corresponds to the ODS selection that is produced
  by the \cs{Listing} tag. All ODS objects of type `Table' are
  selected (more precisely, all objects that are not of type `Graph').
  Each object is contained in its own selection group, so
  a page break might occur between any of the tables.

\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
   Objects                            Type  Status   Group

   Corresp.Inertias                   Table Selected   1
   Corresp.Rows.RowCoors              Table Selected   2
   Corresp.Columns.ColCoors           Table Selected   3
   Corresp.Configuration.ConfigPlot   Graph            .
\end{verbatim}
\end{snugshade}
\caption{SAS Log Information Table from the Listing Tag}\label{loglstinfo}
\end{figure}

  The second information table corresponds to the ODS selection that is produced
  by the \cs{Graphic} tag. The single ODS object of type `Graph' is
  selected.

\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
   Objects                            Type  Status   Group

   Corresp.Inertias                   Table            .
   Corresp.Rows.RowCoors              Table            .
   Corresp.Columns.ColCoors           Table            .
   Corresp.Configuration.ConfigPlot   Graph Selected   1
\end{verbatim}
\end{snugshade}
\caption{SAS Log Information Table from the Graphic Tag}\label{loggraphinfo}
\end{figure}


\section{Specifying and Capturing ODS Objects by Name}
\index{ODS object selection}
  To capture particular ODS objects or ODS group output, you
  must specify the appropriate names in the \cs{Listing} tag,
  the \cs{Graphic} tag, or the \Code{\%write} macro.
  The options that support specific ODS names are
  the \Code{pattern=},
  \Code{firstobj=}, \Code{lastobj=}, or \Code{objects=} options.

  If an object appears more than once in a particular ODS document
  (which typically means in one \Code{Sascode} block), you must specify additional
  name levels to differentiate the objects. The log information table
  displays the fully qualified ODS names; you use the information from
  the log to specify the appropriate name for the ODS objects to capture.

  For example, if there are multiple residual panels,
  you must specify the additional level to select a particular
  ODS object.

\begin{snugshade}
\begin{verbatim}
   objects=residualplot
\end{verbatim}
\end{snugshade}
\begin{snugshade}
\begin{verbatim}
   objects=residualplot\#2
\end{verbatim}
\end{snugshade}

  \textbf{Note:} When you have a pound character (\#) in a pattern or object name,
  you must escape it in \LaTeX\ tags. The pound character is a special \LaTeX\ control
  character and must be escaped with a backslash.
  In other words, specify \Code{Group\textbackslash{}\#2} instead of
  \Code{Group\#2} in a \LaTeX\ tag.
  Do not escape the \# when you use the \Code{\%write} macro.

  Comparisons are not case sensitive. For example, if you specify \Code{pattern=fit},
  the following objects will be selected if they occur in the output stream:
\begin{snugshade}
\begin{verbatim}
Fit.Population.ANOVA
MODEL1.Fit.Population.ANOVA
Reg.MODEL1.Fit.Population.ANOVA
reg#1.model1#1.fit#1.population#1.anova#1
reg#1.model1.fit.population#1.anova#1
reg.model1.fit.population.anova
\end{verbatim}
\end{snugshade}

  Typically\footnote{When deciding on names to specify, be sure to consult the table of names
  from the ODS document that appears in the SAS log. It contains the proper pattern
  of \# characters. See Figure \ref{loginfo} for an example.},
  you need only to specify the last level of an ODS name.
  For example, for one model and one ANOVA table,
  all of the following specifications for the ANOVA object are equivalent.

\begin{snugshade}
\begin{verbatim}
   anova
   ANOVA
   ANOVA\#1
   Fit.Population.ANOVA
   MODEL1.Fit.Population.ANOVA
   Population.ANOVA
   Reg.MODEL1.Fit.Population.ANOVA
   reg.model1.fit.population.anova
   reg\#1.model1.fit.population\#1.anova\#1
   reg\#1.model1\#1.fit\#1.population\#1.anova\#1
\end{verbatim}
\end{snugshade}

  When you run the SAS program that is generated by the \StatRep package,
  the SAS log contains a table with information about each ODS object.
  For example, Figure \ref{capturelist} shows a \Code{Sascode} environment that
  is parsed and written to the generated SAS program when the \LaTeX\ document
  is compiled.
\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
\begin{Sascode}[store=Ex31]
proc probit data=news;
   class subs sex;
   model subs=sex age / d=logistic itprint;
run;
\end{Sascode}

\Listing[store=Ex31,
  objects=ClassLevels IterHistory ModelInfo
          LastGrad LastHess ParameterEstimates,
  caption={Logistic Regression of Subscription Status}]{prb31a}

\end{verbatim}
\end{snugshade}
\caption{Example of Capturing Listing Output}\label{capturelist}
\end{figure}

The \cs{Listing} tag results in a call to the \Code{\%write} macro in the
automatically generated SAS program. When you execute the program,
the \Code{\%write} macro generates the log information table shown in
Figure \ref{loginfo}.

\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
   Objects                     Type  Status   Group

   Probit.IterHistory          Table Selected   1
   Probit.ModelInfo            Table Selected   2
   Probit.NObs                 Table            .
   Probit.ClassLevels          Table Selected   3
   Probit.ParmInfo             Table            .
   Probit.ResponseProfile      Table            .
   Probit.Note                 Note             .
   Probit.LastGrad             Table Selected   4
   Probit.LastHess             Table Selected   5
   Probit.ConvergenceStatus    Table            .
   Probit.Type3Analysis        Table            .
   Probit.ParameterEstimates   Table Selected   6
\end{verbatim}
\end{snugshade}
\caption{SAS Log Information Table}\label{loginfo}
\end{figure}

  The table of information displays the fully qualified name for each
  generated ODS object, its type, whether it is selected, and its
  selection group.

  Page breaks can occur only between
  selection groups. You can control the grouping
  as described in the section \ref{pagebreak} on page \pageref{pagebreak}.
  For example, if you specify
\Code{LastGrad LastHess} as \Code{<LastGrad LastHess>},
  the two tables would be in the same group.

  The order in which objects are created is determined by the
  order in which they are generated, not the order in which they are
  specified in the \Code{objects=} option.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\part{Reference Manual}
\chapter{Overview}

The preceding pages should provide the information to use the package
in most scenarios. For more in-depth descriptions and methods for
customization, see the following chapters.

\begin{description}
\item[Customizing \StatRep] describes several hooks for customizing
the package and setting system-wide defaults.
\item[About the Program Preamble] provides an overview of how the \StatRep
package works with the SAS macros; a special file (the program preamble)
provides a method of communication between the two.
\item[Two Methods of Writing] describes how you can bypass the automatic
code generation and use the \StatRep SAS macros directly.
\item[\StatRep SAS Macros] describe in detail each SAS macro in the
\StatRep package. You can use these macros yourself for maximum flexibility
in creating a custom \StatRep document.
\item[ODS Object Selection] describes how you can use options in the
\cs{Listing} and \cs{Graphic} tag to specify exactly what output you want
to display.
\item[ODS Graphics] describes differences between ODS graphics and
GRSEG graphics.
\end{description}

\chapter{Customizing \StatRep}\label{custom}
 \index{customizing}\index{configuration}

  You can modify the configuration file \Code{statrep.cfg} to change
the following settings used by the \StatRep package.
  See section \ref{secdefaults} for more information about macro variable defaults.

    \begin{description}
     \item[\cs{SRcaptionfont}] specifies the font for the output captions.
     The default is \cs{sffamily} (\textsf{sans serif}).
     \index{caption font}

     \item[\cs{SRcaptioncontinuedfont}] specifies the font for the \Code{continued} name
     for outputs that break across pages.
     The default is \cs{sffamily}\cs{itshape} (\textsf{\textit{sans serif, italic}}).

     \item[\cs{SRcontinuedname}] specifies the name that indicates that an output
     block is continued. The name is used when an output stream breaks across a page.
     The default is \Code{continued}.

    \item[\cs{SRdefaultdests}] specifies the default ODS Destination for tabular
    outputs. The default is \Code{listing}. You can specify \Code{latex} to produce
    SAS-generated LaTeX tabular output. See appendix \ref{latexoutput} for details.
    \index{LaTeX output}

    \item[\cs{SRdpi}] specifies the default dots per inch (DPI) for SAS to use in generating
    graphical output. The default is \Code{300}.
    \index{dpi}

    \item[\cs{SRgraphicdir}] specifies the name of the directory that contains the SAS
     generated graphical output files. The default is \Code{png}.
     \index{graphic directory}

    \item[\cs{SRgraphtype}] specifies the format of the SAS
     generated graphical output. You can specify either
     \Code{png} or \Code{pdf}. The default is \Code{png}.
     \index{graphics type}\index{PNG graphics}\index{PDF graphics}

    \item[\cs{SRlatexdir}] specifies the name of the directory that contains the
    SAS generated LaTeX tabular output. The default is \Code{tex}.
    See appendix \ref{latexoutput} for details.

    \item[\cs{SRlatexstyle}] specifies the ODS style for SAS to use to generate
    LaTeX tabular output. The default is \Code{statrep}, a monochromatic style based
    on the \Code{statistical} ODS style.
    See appendix \ref{latexoutput} for details.

    \item[\cs{SRodsgraphopts}] specifies a string that is passed as
    ODS GRAPHICS statement options. For a complete explanation of all available options,
    see the documentation of the ODS GRAPHICS statement in
    \textit{SAS Output Delivery System: User's Guide}.
    \index{ODS graphics options}

    \item[\cs{SRintertext}] specifies the text to insert in
    \Code{Datastep} environments that specify
     the \Code{first=} option. The default is \Code{\mbox{... more data lines ...}}

    \item[\cs{SRlinesize}] specifies the default line size to use in generating tabular
    output and centering it for display. The default is \Code{80}.
    \index{output width}\index{linesize}

     \item[\cs{SRlistingdir}] specifies the name of the directory that contains the SAS
     generated listing (tabular) output files. The default is \Code{lst}.

     \item[\cs{SRmacropath}] specifies the path to the location of the
     SAS macros that are bundled with the \Code{StatRep} package.
     \index{SAS macro location}
     For example, if  you installed the \Code{statrep\_macros.sas} file to a directory named
    \Code{C:\textbackslash mymacros},
    then define macro \cs{SRmacropath} as follows:
    \begin{verbatim}
    \def\SRmacropath{c:/mymacros/statrep_macros.sas}
    \end{verbatim}

   Use the forward slash in the definition
   as the directory name delimiter instead of the backslash, which is a special
   character in \LaTeX. If you want to use a backslash character (\textbackslash), you
   must insert it with the \LaTeX\ command, \cs{@backslashchar}.

   The default value is the current path. That is, the default
   definition for the \cs{SRmacropath} macro is the filename itself, \Code{statrep\_macros.sas}.

     \item[\cs{SRmacroinclude}] specifies the line used in the generated SAS program to
     include the SAS macros that are bundled with the \Code{StatRep} package.
     The default is\\\Code{\%include }\cs{SRmacropath}~\Code{/nosource;}

    \item[\cs{SRpagesize}] specifies the default page size for SAS to use in generating
    tabular output. The default is \Code{500}.


     \item[\cs{SRparindent}] specifies the amount of space to indent
     \Code{Datastep} and \Code{Sascode} environments.
     The argument is a dimension.
     The default is \Code{3em} and is measured according to the font currently in use.

     \item[\cs{SRprogramline}] specifies the first lines to include in the generated SAS program
     after the \cs{SRmacroinclude} line.

     The following default value calls a macro (from \Code{statrep\_macros.sas})
     that removes the contents of the listing and graphic directories to ensure
     that the generated graphs and listings from the SAS program are current.
     The directories are created with
     each SAS run that includes the macros themselves (via \Code{x} commands).
\begin{snugshade}
\begin{verbatim}
   %hostdel;
\end{verbatim}
\end{snugshade}

      \item[\cs{SRprogramname}] specifies the filename for the generated SAS
     program. The default is \cs{jobname\_SR.sas}, where \cs{jobname} is
     usually the stem name of the \LaTeX\ source file.


    \item[\cs{SRstyle}] specifies the default ODS style for SAS to use to generate
    graphical output. The default is \Code{Statistical}.
    \index{ODS output style}

     \item[\cs{SRtempfilename}] specifies the name of a temporary file
     that is used as a scratch file in the current working directory.
     The default is \Code{sr.tmp}.

     \item[\cs{SRverbfont}] specifies the font to use for code within \Code{Datastep} and
     \Code{Sascode} blocks. The default is \cs{ttfamily}\cs{bfseries}
     (\texttt{\textbf{typewriter text, bold}}).
     \index{verbatim font}

     \end{description}

  \chapter{About the Program Preamble}

The \StatRep package automatically writes a preamble to the generated program and a preamble file.

The preamble settings are split into two parts to support users who prefer to
manually write the calls to the \StatRep macros and work interactively between the
\LaTeX\ source document and a SAS session.  For this use, you can include the external
preamble file once in your SAS session and all the necessary settings are made for you.

If you do not manually write calls to the \StatRep macros (you use the default, automated method),
there is nothing you need to do---your generated program contains the lines that specify your settings.

The preamble in the generated program includes the preamble file and deletes the contents of the
output directories (\Code{lst}, \Code{tex}, and \Code{png}, by default) so that obsolete files are
not included in the document.
Figure \ref{fig:pgmpreamble} shows an example of the preamble lines
that are written to the generated program.
\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
/*
 This file is auto-generated by the statrep package.
 Do not edit this file or your changes will be lost.
 Edit the LaTeX file instead.

 See the statrep package documentation and the file
 statrep.cfg for information on these settings.
 */


%include "report_SR_preamble.sas" /nosource;
/* Remove all output files. */
%hostdel;

/* Start program with a null title. */
title;
\end{verbatim}
\end{snugshade}
\caption{Generated SAS Program Preamble}\label{fig:pgmpreamble}
\end{figure}

  The external preamble file sets defaults, includes
  the output-capture macros, and creates the output directories if they do not exist.
  You can customize the preamble; see section \ref{custom} for details.
  Figure \ref{fig:preamble} shows the default file preamble.
\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
/*
 This file is auto-generated by the statrep package.
 Do not edit this file or your changes will be lost.
 Edit the LaTeX file instead.

 See the statrep package documentation and the file
 statrep.cfg for information on these settings.
 */


/* Set and invoke macro variable defaults. */
%let defaultlinesize=80;
%let defaultpagesize=500;
%let defaultdpi=300;
%let defaultstyle=statistical;
%let listingdir=lst;
%let graphicdir=png;
%let graphtype=png;
%let odsgraphopts=;
%let latexdir=tex;
%let latexstyle=statrep;
%let defaultdests=listing;

options nodate nonumber
ls=&defaultlinesize ps=&defaultpagesize
formchar='|----|+|---+=|-/\<>*';

ods graphics on;
/* Include SAS macro definitions. */
%include "statrep_macros.sas" /nosource;

\end{verbatim}
\end{snugshade}
\caption{Generated Preamble File}\label{fig:preamble}
\end{figure}

\chapter{Two Methods of Writing}
  To maximize flexibility, the \StatRep package provides two methods of writing code in your
\LaTeX\ document.

When you create your \LaTeX\ document, you can use either the automatic method described in
chapter \ref{gs} (in which the SAS macro calls are generated automatically) or a manual
method (in which you write the \Code{\%output}, \Code{\%endoutput}, and \Code{\%write} macros yourself).

In the automatic method, each \Code{Sascode} code block generates an \Code{\%output} macro call at the beginning
of the block and an \Code{\%endoutput} macro call at the end of the block.
Each \cs{Listing} and \cs{Graphic} tag generates the \Code{\%write}
macro to replay the selected output objects to external files.

In the manual method, you decide where and when to make the macro calls.
It is only in this respect that the method is manual: the
\StatRep package still generates your SAS program and displays your code and results.

The \StatRep package uses
  the SAS macro comment (\Code{\%* \emph{comment} ;}) to provide line
  commands within a \Code{Sascode}
  block. Furthermore, any line of code that begins with a null macro
  comment (\Code{\%*;})
  is written to the SAS program and is not displayed.

You can use the manual method when you want to do one or more of the following:
\begin{itemize}
\item capture specialized or complicated output
\item capture print output with SAS 9.2 (see the \Code{\%startlist} macro in section \ref{startlist})
\item capture output from the SAS log (see the \Code{\%startlog} macro in section \ref{startlog})
\item work interactively when writing (you can interactively develop or debug a
        certain section of your document by copying code from
        your \LaTeX\ document and pasting it into a SAS session)
\end{itemize}

 You can use either method, and you can
mix the methods in a single document. The manual method is provided for cases in which the
automatic method is too inflexible. By using the line commands in a \Code{Sascode} environment,
you are free to write your program as you want, while retaining control of the code that is
displayed in your final PDF document.

  Continuing with example shown in Figure \ref{fig:d1} and Figure \ref{fig:s1},
  you can write the code yourself within your
  \LaTeX\ document as shown in Figure \ref{fig:manual}
  and obtain the identical code display and capture.

\begin{figure}[H]
\begin{framed}
\begin{snugshade}
{\hfil\textit{Datastep is identical}\hfil}
\begin{verbatim}
\begin{Datastep}
proc format;
   value $sex 'F' = 'Female' 'M' = 'Male';
data one;
   set sashelp.class;
   format sex $sex.;
run;
\end{Datastep}
\end{verbatim}
\end{snugshade}
\begin{snugshade}
{\hfil\textit{\texttt{\%output} added manually}\hfil}
\begin{verbatim}
\begin{Sascode}
 *; %output(class)
proc reg;
    model weight = height age;
run;
\end{verbatim}
\end{snugshade}
\begin{snugshade}
{\hfil\textit{\texttt{\%write} macros added manually}\hfil}
\begin{verbatim}
 *; %write(rega, type=listing)
 *; %write(regb, type=graphic)
\end{Sascode}
\end{verbatim}
\end{snugshade}
\begin{snugshade}
{\hfil\textit{Listing and Graphic tags only caption and insert output}\hfil}
\begin{verbatim}
\Listing[caption={Regression Analysis}]{rega}
\Graphic[caption={Graphs for Regression Analysis}]{regb}
\end{verbatim}
\end{snugshade}
\end{framed}
\caption{Using the SAS Macros Manually}\label{fig:manual}
\end{figure}

  The \Code{Datastep} environment in Figure \ref{fig:manual} is identical to that shown in the
  Figure \ref{fig:d1}. However, the \Code{Sascode}
  environment makes an explicit call to the \Code{\%output} macro to create
  the ODS document that contains all the results from the code block.
  Because this line begins with the null SAS macro comment (\Code{\%*;}), the line
  is passed directly to the generated SAS program and is not displayed.

  The \Code{\%endoutput} macro is not necessary when you are processing
  only one ODS document. It is implicitly specified by the first \Code{\%write} macro.

  Next are two explicit calls to the \Code{\%write} macro, which
  specify the ODS objects to capture and the ODS document that the objects
  should be taken from.
  Both \Code{\%write} macros use the minimum number of options.
  The first \Code{\%write} macro selects all
  notes and tables from the last ODS document created. The second \Code{\%write} macro
  selects all graphs from the last ODS document created.
  Because the \Code{store=} option is omitted in both cases,
  output from the most recently created ODS document is displayed.

  Finally, the \cs{Listing} and \cs{Graphic} tags request the outputs.
  In
  this method, you do not place the options that are related to SAS in the
  the \cs{Listing} and \cs{Graphic} tags. You need to
  specify only the caption and filename prefix.


  To summarize, the \Code{Datastep} environment is handled identically in either method,
  the \Code{Sascode} environment can optionally produce the \Code{\%output} and \Code{\%endoutput} macros,
  and the \cs{Listing} and \cs{Graphic} tags can optionally produce the \Code{\%write} macros.

\chapter{\StatRep SAS Macros}\label{macros}
\index{SAS macros}
  SAS programs created by the \StatRep package
  run SAS macros to capture output. The macros depend on the ODS document.
  The ODS document is a destination or repository for the results
  (tables, notes, titles, and graphs)
  that come from SAS procedures. Each procedure step is run only once,
  and the results are captured in an ODS document.
  Then the parts of the ODS document are replayed using PROC DOCUMENT.

  When \StatRep encounters a \Code{Sascode} environment,
  it generates a macro call to create an ODS document from the environment.
  When \StatRep encounters a \cs{Listing} or \cs{Graphic} tag,
  it generates a macro call to replay output from that ODS document into an external file.

  For the output that is generated in each \Code{Sascode} block, the SAS macros provide you
  with a list of all
  of the objects in the ODS document and a table that displays
  the objects selected for display. You can
  review this list in the SAS log.
  It is important to check these lists to ensure that either all output
  is included somewhere or any omissions are deliberate.

  The following macros are defined:
  \begin{itemize}
  \item The \Code{\%output} and \Code{\%endoutput} macros open and close an ODS document, respectively.
  When you use \StatRep to automatically generate your program, these macros are called at the
  beginning and end of a \Code{Sascode} block, respectively.
  You can manually call the macros at any time within
  a \Code{Sascode} block by prefixing the call with a null SAS macro comment (\Code{\%*;}).
  \index{SAS macros!output}\index{SAS macros!endoutput}

  \item The \Code{\%write}  macro writes ODS objects that are contained in an ODS document to
  one or more external files.
  When you use \StatRep to automatically generate your program, this macro is called when
  a \cs{Listing} or \cs{Graphic} tag is encountered. You can manually call the macro
  at any time within a \Code{Sascode} block by prefixing the call with a null
  SAS macro comment (\Code{\%*;}).
  \index{SAS macros!write}

  \item The \Code{\%startlist} and \Code{\%endlist} macros capture printed content
  (for example, a PROC PRINT or DATA step) to an external file. To use these macros,
  you must manually call the macro
  within a \Code{Sascode} block and prefix the call with a null
  SAS macro comment (\Code{\%*;}).
  \index{SAS macros!startlist}\index{SAS macros!endlist}

  \item The \Code{\%startlog} and \Code{\%endlog} macros capture content from the
  SAS log to an external file. To use these macros,
  you must manually call the macro
  within a \Code{Sascode} block and prefix the call with a null
  SAS macro comment (\Code{\%*;}).
  \index{SAS macros!startlog}\index{SAS macros!endlog}
  \end{itemize}


  \section{The \texttt{\%output} and \texttt{\%endoutput} Macros}\label{outputmacro}
  The \Code{Sascode} environment writes the \Code{\%output} and \Code{\%endoutput} macros to
  the generated program
  whenever the \Code{store=} option is specified.
  However, you can call the macros
  yourself by omitting the \Code{store=} option in the \Code{Sascode} environment and
  call the macros within the \Code{Sascode} environment. Each call must be prefixed
  with a null SAS macro comment (\Code{\%*;}).
  \index{SAS macros!output}\index{SAS macros!endoutput}

  The \Code{\%output} macro supports two other options (\Code{style=} and \Code{dpi=}) that are used to
  set parameters for GRSEG graphs. These options are not supported in the
  \Code{Sascode} environment options. If you want to change the style or DPI for
  GRSEG graphs, you must call the \Code{\%output} and \Code{\%endoutput} macros manually.

  The following options are supported by the \Code{\%output} macro:
 \begin{description}
 \item[\Code{store=}] specifies the name of the ODS document.
  This name is used in the \Code{store=} option in the \cs{Listing} and \cs{Graphic} tags
  or in the \Code{\%write macro}.

 \item[\Code{style=}] specifies the style used for GRSEG graphs.
 The default is \Code{HTMLBlue}. See section \ref{grseg} for details.

 \item[\Code{dpi=}] specifies the dots per inch (DPI) setting used for GRSEG graphs.
  The default is 300 DPI. See section \ref{grseg} for details.
 \end{description}


  \section{The \texttt{\%write} Macro}
  The \Code{\%write} macro supports the same key-value options as the \cs{Listing} and
  \cs{Graphic} tags support.
  The \StatRep package generates the \Code{\%write} macro in the SAS program
  file whenever the \Code{store=} option is specified in the output tag.
  However, you can call the macros
  yourself by omitting the \Code{store=} option in the \cs{Listing} or \cs{Graphic}
  tag and call the macro within a \Code{Sascode} environment. Each call must be prefixed
  with a null SAS macro comment (\Code{\%*;}).
  \index{SAS macros!write}
See the section \titleref{sasopts} for more information about the options used in the
\cs{Listing} and \cs{Graphic} tags that are passed to the \Code{\%write} macro.


\vspace*{1em}\noindent\textbf{Note:} If you use the macros interactively, be aware that
these macros open and close ODS destinations,
enable and disable ODS Graphics, and change ODS options.  Output capture uses the
LISTING destination, and when the \Code{\%write} macro finishes, only the
LISTING destination remains open.
If you need other ODS destinations for your work, you need to reset them
when you are done with a section of output capture.  For example,
if you are using the HTML destination
in the SAS windowing environment, then you need to
close the LISTING destination and reopen the HTML destination when you finish
capturing output.

 \section{The \texttt{\%startlist} and \texttt{\%endlist} Macros}\label{startlist}

  The \Code{\%startlist} and \Code{\%endlist} macros capture printed information
  from the ODS listing destination. The macros are used when
  you create output with a procedure that does not support ODS.
  They are also used when you use the
  \Code{DATA \_NULL\_} and \Code{PUT \_ODS\_} SAS statements to
  manually capture output.
  \index{SAS macros!startlist}\index{SAS macros!endlist}

  These macros are not automatically generated by the \StatRep package.
  You must call them
  manually within a \Code{Sascode} environment (with each call preceded
  by a null SAS macro comment).

  In SAS 9.2, PROC PRINT is not fully integrated into the ODS document,
  unless you specify PROC PRINT with no options.
  If you specify PROC PRINT
  with options, you must use the \Code{\%startlist} and \Code{\%endlist}
  macros to capture output.

  If you use PROC PRINT in SAS 9.3 or later,
  you can use the \Code{\%output} and \Code{\%write} macros as you would with
  any SAS procedure.

  The \Code{\%startlist} macro has one mandatory argument, the filename prefix
  of the file to contain
  the output. The argument is also used
  in the \cs{Listing} tag to insert the output.

  The \Code{\%startlist} macro supports the following options after
  the filename argument, separated with a comma (,):
  \begin{description}
  \item[\Code{linesize=}] specifies the line size.
  The default is the line size currently in effect.
  This specification lasts for the duration of this step.
  The current line size is restored at the end.
  When you specify the \Code{linesize=} option in the \Code{\%startlist}
  macro, be sure to make the same specification
  in the \cs{Listing} tag you use to insert the output.

  \item[\Code{pagesize=}] specifies the size of the output page.
   The default is the page size currently in effect.
   This specification lasts for the duration of this step.
  The current page size is restored at the end.
  This option is useful for breaking up long listings into smaller parts to allow for page breaks.
  If a listing output spans more than one SAS page,
  the output is automatically split into parts and the page breaks
  can occur only between parts of output.
  For more information about capturing large outputs, see section \ref{large}.
  \end{description}

 \section{The \texttt{\%startlog} and \texttt{\%endlog} Macros}\label{startlog}

  The \Code{\%startlog} and \Code{\%endlog} macros capture SAS notes
  or error messages from the SAS log. They also capture output
  from some SAS/IML functions that write to the SAS log rather than using ODS.
  \index{SAS macros!startlog}\index{SAS macros!endlog}

  These macros are not automatically generated by the \StatRep package.
  To capture content from the SAS log, you must call these macros
  manually within a \Code{Sascode} environment (with each call preceded
  by a null SAS macro comment).

  The \Code{\%startlog} macro has one mandatory argument, the filename prefix
  of the file to contain the output. The argument is also used in the \cs{Listing}
  tag to insert the output.

  The \Code{\%endlog} macro supports the following options,
  separated by a comma (,):

  \begin{description}
  \item[\Code{code=}] specifies whether program code in the SAS log is included.
  By default, code is captured (\Code{code=1}). Set \Code{code=0} to exclude code.
  \item[\Code{range=}] specifies a Boolean expression to select
  certain observations. For example, you can specify \Code{range=\_n\_ <= 5 }
  to select the first five lines.  You can specify
  \Code{range=not index(line, 'ERROR')} to select all lines that do not contain the string
  `ERROR'. Selection must be based on \Code{\_n\_} or the variable \Code{line}, which
  contains a single line of the log.
  \end{description}

  \section{Macro Variable Defaults}\label{secdefaults}
  \index{macro variables}\index{default settings}\index{package!defaults}
  \index{SAS macros!variables}

  The SAS macro defaults are set globally in the file \Code{statrep.cfg}.
  See section \ref{custom} for details. You can also reset the
  defaults within your document by specifying new settings in a \Code{Sascode}
  environment.

  Table \ref{defaults} shows the description and default values for each
  macro variable.

  \begin{table}[H]
  \centering\caption{Default Values for Macro Variables}\label{defaults}
  \begin{tabular}{llP{2.5in}}
  \textbf{Macro Variable}    & \textbf{Default} & \textbf{Description}\\
  \hline
    \Code{defaultlinesize}  & 80      & Line size for tabular ODS output\\
    \Code{defaultpagesize}  & 500     & Page size for tabular ODS output\\
    \Code{defaultstyle}     & Statistical & ODS style for graphical output \\
    \Code{defaultdpi}       & 300      & Dots per inch (DPI) for graphical output\\
    \Code{graphtype}        & png      & graphics file format ('png' or 'pdf')\\
    \Code{odsgraphopts}     &          & string containing ODS graphics options\\
    \Code{defaultdests}     & listing  & \texttt{listing} or \texttt{latex} tabular output\\
    \Code{latexstyle}       & statrep  & ODS Style for SAS-generated LaTeX output\\
  \hline
   \end{tabular}
  \end{table}

  You can edit the \Code{statrep.cfg} file\index{customizing}\index{statrep.cfg}
  \index{configuration}%
  to globally reset the defaults, or you can specify commands to change the default anywhere
  in your document. For example, the following lines change all of the macro variable
  default settings for the duration of the program. The \Code{program} option specifies
  that the code be written only to the generated program and not displayed.


\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
   \begin{Sascode}[program]
   %let defaultlinesize=96;
   %let defaultpagesize=50;
   %let defaultstyle=statistical;
   %let defaultdpi=100;
   %let graphtype=pdf;
   %let odsgraphopts=antialiasmax=10000;
   \end{Sascode}
\end{verbatim}
\end{snugshade}
\caption{Reset SAS Macro Defaults within Document with SAS}\label{reset}
\end{figure}

  When you change the \Code{defaultlinesize} in the \Code{statrep.cfg} file, the same value
  is automatically used by SAS and by the \StatRep package.
  When you change the \Code{defaultlinesize} inside your document,
  you change the line size used by SAS in generating
  outputs; You must also set the line size in the \cs{Listing} tag to match.

  The setting of \Code{defaultpagesize=500} produces a large
  virtual page so that SAS does not break ODS objects into smaller pieces.
  When a stream of outputs is typeset, page breaks can occur only between ODS objects or
  when SAS forces a page break inside an ODS table.

  The macro options and default macro variables work as follows:
  If an option is specified in a macro, its value is used regardless of
  the specification in the default macro variables.
  If an option is not specified in a macro, the default macro variables provide
  the values.

  In summary, a direct option specification in a macro takes precedence over the default
  settings, and you can change the default settings by resetting the
  default macro variables
  in your document or by editing the \Code{statrep.cfg} file.

 \chapter{ODS Object Selection}\label{selection}
To select and display ODS objects, you specify options in the \cs{Listing} tag, \cs{Graphic}
  tag, or the \Code{\%write} macro.
\label{optionopt}
By default, when you omit object selection options, the \Code{\%write} macro selects all ODS objects,
the \cs{Listing} tag selects all ODS tables and notes, and the \cs{Graphic} tag selects all ODS graphs.
\index{ODS object selection}
  Table \ref{tabselect} summarizes how you select ODS objects.
  \begin{table}[H]
  \centering\caption{ODS Object Selection Options}\label{tabselect}
  \begin{tabular}{lP{3.75in}}
  \textbf{Option}  & \textbf{Action}\\
  \hline
  \Code{options=table}    & Select all tables and notes\\
  \Code{options=graph}    & Select all graphs \\
  \Code{pattern=} \textit{pattern}   &
Select all objects with a name matching a pattern.
When an ODS object name has more than two levels,
  the middle level name is a group name. You can specify the \Code{pattern=} option
  to select all ODS objects in the specified ODS group.
  More generally, you can specify any pattern to select all objects
  whose path contains the pattern.\\
  \Code{firstobj=} & Specifies the first object in the output stream to capture.
  The specified and subsequent objects are captured.\\
  \Code{lastobj=}  & Specifies the last object in the output stream to capture.
The first object in the stream to capture is the first object produced by the
\Code{Sascode} code block or the object specified in the \Code{firstobj=} option.\\
  \Code{objects=} option & Specifies a space-separated list of objects to capture.\\
  \hline
  \end{tabular}
  \end{table}

  The \Code{firstobj=} and \Code{lastobj=} options can be modified with the option
  \Code{options=skiplast} and  \Code{options=skipfirst}. For more information about
  how to use these options,
  see page \pageref{skiplast}.

  \section{Page Breaks}\label{pagebreak}
  By default, a page break can occur between any two objects in the output stream.
  However, you can use left and right angle brackets, \Code{<>},  to delineate a
  set of objects in which to suppress breaks.
  You use the symbols in the \Code{objects=} option list in
  a \cs{Listing} tag, a \cs{Graphic} tag, or a \Code{\%write} macro.


  For example, you can use the symbols to prevent a break between a
  ``Parameter Estimates'' table and the ``Fit Statistics'' table that follows it
  with the following option:
  \Code{objects = < ParameterEstimates FitStatistics >}

  After the \Code{<} symbol, breaking is suppressed until the \Code{>} symbol is encountered.
  After the \Code{>} symbol, a break is introduced and normal breaking continues.

  In summary:
  \begin{itemize}
  \item You can use the \Code{<>} symbols in pairs to keep ODS objects together.
  \item You can use the \Code{>} symbol (unpaired with a matching \Code{<}) to create a break between tables.
  \item You can use the \Code{<} symbol (unpaired with a matching \Code{>}) to suppress all breaks.
  \end{itemize}

  A break is always allowed before and after a graph.

  See page \pageref{skiplast} for an alternate method of controlling breaks
  with the \Code{options=nopage} and \Code{options=onebox} options.

 \chapter{ODS Graphics}
 \index{ODS graphics}

 In SAS 9.3 and later, ODS Graphics is enabled by default in the SAS windowing environment.
 ODS Graphics is not enabled by default in batch mode and in the SAS windowing environment in SAS 9.2.
 When ODS Graphics is not enabled by default, you can enable ODS Graphics by specifying the following statement:

\begin{snugshade}
\begin{verbatim}
   ods graphics on;
\end{verbatim}
\end{snugshade}


You can enable ODS Graphics in \StatRep for all steps by providing this code block at the
beginning of your LaTeX document:

\begin{snugshade}
\begin{verbatim}
   \begin{Sascode}[program]
      ods graphics on;
   \end{Sascode}
\end{verbatim}
\end{snugshade}

 \section{ODS Graphics and GRSEG Graphics}
 \label{grseg}
  \index{ODS graphics}\index{GRSEG graphics}
  When you create a graph with ODS Graphics, the style and dots per inch (DPI) can be changed
  after the graph is created. The style and DPI are set when the
  graph is written to the external file. This enables you to specify the options
  in the \cs{Graphic} tag or in the \Code{\%write} macro.

  On the other hand, when you create a GRSEG graph, the style and DPI
  are set when the graph is created. That is why you must specify the options
  in the \Code{\%output} macro. See section \ref{outputmacro} for details
  about the \Code{\%output} macro options.

  Table \ref{tabgraph} summarizes the methods you can use to modify the
  style and DPI settings when you create a graph.

  \begin{table}[H]
  \centering
  \caption{Methods to Change Graph Properties}\label{tabgraph}
  \begin{tabular}{lcc}
  \textbf{Method}          & \textbf{ODS Graph} & \textbf{GRSEG Graph} \\
  \hline
  \cs{Graphic} tag options &  Yes         & No    \\
  \Code{\%write} macro options   &  Yes         & No    \\
  \Code{\%output} macro options  &   No         & Yes   \\
  Reset global default     &  Yes         & Yes   \\
  \hline
  \end{tabular}
  \end{table}

  The \cs{Graphic} tag, the \Code{\%write} macro, and the
  \Code{\%output} macro have \Code{style=} and \Code{dpi=} options. For more information
  about these options, see section \ref{sasopts}.
  Also, see section \ref{secdefaults} for details about
  using the SAS macro variables to reset global defaults.

  For GRSEG graphs, there are only two choices for DPI: 300 (the default) and 96.
  When the DPI is set to anything other than 300,
  then 96 is automatically used instead for GRSEG graphs.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Advanced Examples}


\section{Capturing PRINT Output}\index{SAS macros!startlist}\index{SAS macros!endlist}
  Figure \ref{printoutput} shows simple use of the \Code{\%startlist} and \Code{\%endlist}
  macros.

\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
\begin{Sascode}
 *; %startlist(myprtlabel);
   proc print data=sashelp.class(obs=10) noobs;
   run;
 *; %endlist;
\end{Sascode}

\Listing[caption={Mass Analysis}]{myprtlabel}
\end{verbatim}
\end{snugshade}
\caption{Capturing Print Output with the \texttt{\%startlist} and
\texttt{\%endlist} Macros}\label{printoutput}
\end{figure}

  The \Code{\%startlist} macro opens the ODS listing destination for writing.
  The PRINT procedure code is executed, and the \Code{\%endlist} macro closes the ODS destinations.
  The result is an output file called \Code{myprtlabel.lst}, which is
  inserted into the document with the \cs{Listing} tag.

  The following section describes how to use the \Code{\%startlist} and \Code{\%endlist}
  macros to capture and display part of a table.


\section{Capturing Large Tables}\label{large}

  The \StatRep package automatically takes care of all page breaks in the output.
  Pages are allowed to break between groups of ODS objects or wherever there is a new page
  in the listing output.

  In some cases, an ODS object is too large to fit on a page.
  There are two ways to handle such large tables:
  \begin{itemize}
  \item Set the page size to a smaller size so that a single ODS object is broken into pieces
  by using the SAS system option to control the size of the output parts.
  By default, a large page size is
  in effect (\Code{defaultpagesize=500}) and each table appears
  as a complete output block. However, when you have tables that are
  too long to fit on a page (that is, single ODS objects that will not fit on a page),
  you must specify a smaller page size
  (for example, \Code{pagesize=50}).
  The tables will automatically split using the normal SAS
  rules for splitting tables.

  \item Save the ODS object to a SAS data set and manipulate the data set
  so that it contains only part of the original output. Use PROC PRINT
  or DATA step statements to generate and capture the modified data set.

  \end{itemize}

  Figure \ref{odsdataset} shows an
  example of using a SAS data set to manipulate
  the ODS object resulting from a problem that is very
  slow to converge. The output from this step includes a long iteration
  history table.
  The goal is to display only the first few and last few lines of
  the iteration history table.

\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
\begin{Sascode}[store=doc]
proc prinqual data=X n=1 maxiter=2000
              plots=transformation out=results;
 *; ods output mtv=m convergencestatus=c;
   title 'Linearize the Scatter Plot';
   transform spline(X1-X3 / nknots=9);
run;
\end{Sascode}
\end{verbatim}
\end{snugshade}
\caption{Capturing Output to an ODS Output Data Set}\label{odsdataset}
\end{figure}

  Any arbitrary SAS statement can be sent to the generated program by preceding
  it with a null SAS macro comment (\%*;).
  With the output generated and the ODS document \Code{doc} created,
  the \Code{Sascode} block shown in Figure \ref{odsmanip} is passed directly
  to the generated program and not displayed.

\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
\begin{Sascode}[program]
%startlist(prqdb)
title3 'The PRINQUAL Procedure';
title5 'PRINQUAL MTV Algorithm Iteration History';
title6 '  ';

data _null_;
  set m(rename=(variance=rsquare));
  if _n_ le 13 or _n_ gt 1669;
  if 11 le _n_ le 13 then do;
     iternum   = .; avechange = ._; criterionchange = ._;
     maxchange = ._; rsquare = ._;
     end;
  file print ods=(template='Stat.Transreg.MTV');
  put _ods_;
run;
title;

data _null_;
   set c;
   file print;
   put @8 reason;
run;
%endlist;
\end{Sascode}
\end{verbatim}
\end{snugshade}
\caption{Manipulating the ODS Output Data Set for Printing}\label{odsmanip}
\end{figure}

  The \Code{\%startlist} macro opens the file \Code{prqdb}
   to contain the printed results of the code block.
  The DATA step reads, manipulates, and prints the data set \Code{m}
  that was just created by PROC PRINQUAL, and the printed content is written to the
  output file \Code{prqdb.lst}, which is shown in Figure \ref{odsmanipresult}.

\begin{figure}[H]
\footnotesize
\begin{snugshade}
\begin{verbatim}
                           Linearize the Scatter Plot

                             The PRINQUAL Procedure

                    PRINQUAL MTV Algorithm Iteration History

  Iteration    Average    Maximum     Proportion    Criterion
     Number     Change     Change    of Variance       Change    Note
  -------------------------------------------------------------------------
          1    0.15125    0.93453        0.92376
          2    0.04589    0.14682        0.98030      0.05653
          3    0.03154    0.10125        0.98626      0.00596
          4    0.02258    0.06890        0.98890      0.00265
          5    0.01682    0.04777        0.99028      0.00137
          6    0.01297    0.03782        0.99106      0.00078
          7    0.01032    0.03029        0.99154      0.00048
          8    0.00851    0.02514        0.99186      0.00032
          9    0.00722    0.02124        0.99209      0.00023
         10    0.00625    0.01871        0.99226      0.00017
          .
          .
          .
       1670    0.00001    0.00005        0.99371      0.00000
       1671    0.00001    0.00005        0.99371      0.00000
       1672    0.00001    0.00005        0.99371      0.00000    Converged

       Algorithm converged.
\end{verbatim}
\end{snugshade}
\caption{Result of Printing ODS Output Data Set}\label{odsmanipresult}
\end{figure}


  Similarly, Figure \ref{printods} creates an output data set in the first step.
  The second step reads in the data set and uses PROC PRINT to display
  the first 10 rows of a table.

\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
\begin{Sascode}
   title2 'Binary Table';

   *---Perform Multiple Correspondence Analysis---;
   proc corresp data=Cars binary;
 *;   ods output rowcoors=rc;
      ods select RowCoors;
      tables Origin Size Type Income Home Marital Sex;
   run;
\end{Sascode}
\begin{Sascode}[program]
%startlist(crse1n)
proc print data=rc(obs=10) noobs label;
  label label = '00'x;
  title4 'The CORRESP Procedure';
  title6 'Row Coordinates';
run;
%endlist;
\end{Sascode}
\end{verbatim}
\end{snugshade}
\caption{Capturing PROC PRINT Output from an ODS Data Set}\label{printods}
\end{figure}

\section{Capturing Log Output}
  \index{SAS macros!startlog}\index{SAS macros!endlog}

  The SAS/IML example shown in Figure \ref{logout} illustrates
  the use of the macros that capture log output. In this example, the goal is to
  display SAS/IML error messages\footnote{The example code generates an error because
  of a variable scoping issue.
  Module \Code{Mod7} is called from module \Code{Mod8}. Therefore, the variables
  available to \Code{Mod7} are those defined in the scope of \Code{Mod8}.
  Because no variable named \Code{x} is in the  scope of \Code{Mod8},
  an error occurs on the PRINT statement in \Code{Mod7}.
  An error would not occur if \Code{Mod7} was called from the main scope,
  because \Code{x} is defined at main scope.}.

\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
\begin{Sascode}
 *; %startlog(psmodb)
proc iml;
   x = 123;

   start Mod7;
      print "In Mod7:" x;
   finish;

   start Mod8(p);
      print "In Mod8:" p;
      run Mod7;
   finish;
   run Mod8(x);

 *; %endlog;
\end{Sascode}
\Listing[caption={Error Message When a Variable is
                  Not Defined in a Module}]{psmodb}
\end{verbatim}
\end{snugshade}
\caption{Capturing Log Output}\label{logout}
\end{figure}

  The captured log output is shown in Figure \ref{logcomplete}.


\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
1599 +proc iml;
NOTE: IML Ready
1600 +   x = 123;
1601 +
1602 +   start Mod7;
1603 +      print "In Mod7:" x;
1604 +   finish;
NOTE: Module MOD7 defined.
1605 +
1606 +   start Mod8(p);
1607 +      print "In Mod8:" p;
1608 +      run Mod7;
1609 +   finish;
NOTE: Module MOD8 defined.
1610 +
1611 +   run Mod8(x);
ERROR: Matrix x has not been set to a value.

 statement : PRINT at line 1603 column 7
 traceback : module MOD7 at line 1603 column 7
             module MOD8 at line 1608 column 7

NOTE: Paused in module MOD7.
NOTE: Exiting IML.
NOTE: The SAS System stopped processing this step because of errors.
\end{verbatim}
\end{snugshade}
\caption{Complete Log Output Capture}\label{logcomplete}
\end{figure}

  The \Code{\%startlog} macro opens the specified file for writing, the IML
  procedure code is executed, and the \Code{\%endlog} macro closes the file.

  To omit the PROC IML code from the captured log output,
  specify the \Code{code=0} option in the \Code{\%endlog} macro as follows:

\begin{snugshade}
\begin{verbatim}
   %*; %endlog(code=0);
\end{verbatim}
\end{snugshade}

   With the \Code{code=0} option specified, the captured log output is
   displayed as shown in Figure \ref{lognoproc}.

\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
NOTE: IML Ready
NOTE: Module MOD7 defined.
NOTE: Module MOD8 defined.
ERROR: Matrix x has not been set to a value.

 statement : PRINT at line 1651 column 7
 traceback : module MOD7 at line 1651 column 7
             module MOD8 at line 1656 column 7

NOTE: Paused in module MOD7.
NOTE: Exiting IML.
NOTE: The SAS System stopped processing this step because of errors.
\end{verbatim}
\end{snugshade}
\caption{Log Output Capture: Procedure Code Omitted}\label{lognoproc}
\end{figure}

  You can further refine the captured log output with the
  \Code{range=} option in the \Code{\%endlog} macro as follows:

\begin{snugshade}
\begin{verbatim}
   %*; %endlog(code=0, range=_n_ > 6 and _n_ le 24);
\end{verbatim}
\end{snugshade}
  With the both options specified, the captured log output is displayed as
   shown in Figure \ref{logabbrev}.

\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
NOTE: Module MOD7 defined.
NOTE: Module MOD8 defined.
ERROR: Matrix x has not been set to a value.

 statement : PRINT at line 1722 column 7
 traceback : module MOD7 at line 1722 column 7
             module MOD8 at line 1727 column 7

NOTE: Paused in module MOD7.
\end{verbatim}
\end{snugshade}
\caption{Abbreviated Log Output Capture: Procedure Code Omitted}\label{logabbrev}
\end{figure}

  The \Code{range=\_n\_ > 6 and \_n\_ le 24} option specifies that only the lines between 6 and 24
  be included in the captured output.
  The value of \Code{\_n\_} refers to the original line numbers before any filtering is done.


\section{Capturing Output with Interactive Procedures}
  You can use the \StatRep package to capture output from interactive procedures.
Figure \ref{interact} shows how to capture output from the interactive
  IML procedure.  It displays three \Code{Sascode} environments with \cs{Listing}
  outputs interleaved.

\begin{figure}[H]
\begin{snugshade}
\begin{verbatim}
\begin{Sascode}
 *; %output(doc)
   proc iml;
      x = 1;
      print x;
\end{Sascode}

\Listing[caption={x = 1}]{x1a}

\begin{Sascode}
      x = 2;
      print x;
\end{Sascode}

\Listing[caption={x = 2}]{x2a}

\begin{Sascode}
      x = 3;
      print x;
 *; %write(x1a, objects=x)
 *; %write(x2a, objects=x#2)
 *; %write(x3a, objects=x#3)
\end{Sascode}

\Listing[caption={x = 3}]{x3a}
\end{verbatim}
\end{snugshade}
\caption{Capture Output with an Interactive Procedure}\label{interact}
\end{figure}

  When you need to interleave \Code{Sascode} blocks to make a single ODS
  document, as in Figure \ref{interact}, you cannot rely on the \StatRep package to
  automatically write the macros. You must write the output capture macros manually.

  When the \StatRep package automatically writes the macros, there is a
  one-to-one correspondence between a \Code{Sascode} block and an ODS document.
  The interactive procedure terminates when the ODS document is closed.

  Figure \ref{interact} uses three \Code{Sascode} blocks to create a single ODS document.
  The contents of that ODS document are displayed in three separate listings.
  The ODS document is created by the \Code{\%output(doc)} statement in the first
  \Code{Sascode} environment, and it is closed by the first \Code{\%write}
  macro in the third \Code{Sascode} environment.
  The three \Code{\%write} macros create the output for the
  three output listings.
  The fact that two of the \cs{Listing} lines come before any of the output is
  created does not pose a problem.

\section{Capturing and Displaying Numerical Results in Text}

This example shows how you can capture SAS output values and display them in text.
For example, suppose you want to capture the R-square values from a PROC REG
step and a PROC GLM step and then display those values
(but not display the steps) in your document.

Use the following steps to capture the values and display them in text:

\begin{enumerate}
\item In your document source file, anywhere before you want to display the
      captured values, include the following command to
      input a \LaTeX\ file (named\newline\texttt{myconstants.tex} in this example)
      to contain the \LaTeX\ definitions of the captured values:
\begin{snugshade}
\begin{verbatim}
   \input{myconstants}
\end{verbatim}
\end{snugshade}

The \texttt{myconstants.tex} file is actually generated in step 3,
but you can include the preceding command before the file is generated
because the SAS output capture program will create the file and write
the definitions before pdf\LaTeX\ generates the final PDF file.

\item Include one or more procedure steps, such as the following
      PROC REG and PROC GLM steps, which produce tables of fit statistics
      that are named \texttt{fsr} and \texttt{fsg}, respectively:
\begin{snugshade}
\begin{verbatim}
   \begin{Sascode}
   proc reg data=sashelp.class;
      model weight = height;
   %*;ods output fitstatistics=fsr;
   run; quit;

   proc glm data=sashelp.class;
      class sex;
      model weight = sex | height;
   %*;ods output fitstatistics=fsg;
   run; quit;
   \end{Sascode}
\end{verbatim}
\end{snugshade}

Include a null macro comment at the beginning of the ODS OUTPUT statement
in each step to cause the step to be run in the capture program but not be
displayed in the text.

\item Near the end of your document source file, include code such as the
      following to generate the \texttt{myconstants.tex} file, extract the
      R-square values from the \texttt{fsr} and \texttt{fsg} tables of fit statistics that were
      generated in step 2, and write those values to \texttt{myconstants.tex}.
      The \texttt{Sascode} environment option, \texttt{program},
      runs the code without displaying it in the text.
\begin{snugshade}
\begin{verbatim}
   \begin{Sascode}[program]
   data _null_;
      file 'myconstants.tex' termstr=nl;
      set fsr(keep=label2 nvalue2 where=(label2='R-Square'));
      put '\def \regrsq{' nvalue2 6.4 '}';
      set fsg(keep=rsquare);
      put '\def \glmrsq{' rsquare 6.4 '}';
   run;
   \end{Sascode}
\end{verbatim}
\end{snugshade}

\item Include the tags that are contained
     in the \texttt{myconstants.tex} file when you want to display
     the values of those tags, as follows:
\begin{snugshade}
\begin{verbatim}
   The R-square values are \regrsq\ and \qlmrsq, respectively.
\end{verbatim}
\end{snugshade}
   Include a backslash after the tag when you need to include a space after the value.
\end{enumerate}

When you execute the generated SAS program, SAS writes the
following tags in the \texttt{myconstants.tex} file:
\begin{snugshade}
\begin{verbatim}
   \def \regrsq{0.7705}
   \def \glmrsq{0.7930}
\end{verbatim}
\end{snugshade}

When pdf\LaTeX\ processes the file, it replaces the
\verb+\regrsq+ and \verb+\glmrsq+ tags with the values that were
written to the \texttt{myconstants.tex} file and produces the
following:
\begin{snugshade}
   The R-square values are 0.7705 and 0.7930, respectively.
\end{snugshade}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\appendix
\part{Appendix}
%\chapter{Appendix}

\chapter{Installation and Requirements}\label{install}\index{installing}
You can install the \StatRep package by downloading \Code{statrep.zip} from \url{support.sas.com/StatRepPackage}.

Table \ref{ziptable} shows the contents:
\begin{table}[H]
\caption{Contents of the \Code{statrep.zip} File}\label{ziptable}
\begin{tabular}{ll}
\hline
\textbf{Filename}          &  \textbf{Description}\\
\Code{doc/statrepmanual.pdf}   & The \textit{\StatRep User's Guide} (this manual)\\
\Code{doc/quickstart.tex}      & A template and tutorial sample \LaTeX\ file\\
\Code{sas/statrep\_macros.sas} & The \StatRep SAS macros \\
\Code{sas/statrep\_tagset.sas} & The \StatRep SAS tagset for LaTeX tabular output \\
\Code{statrep.ins}         & The \LaTeX\ package installer file\\
\Code{statrep.dtx}         & The \LaTeX\ package itself\\
\hline
\end{tabular}
\end{table}

Unzip the file \Code{statrep.zip} to a temporary directory and
perform the following steps:

\section{Step 1: Install the StatRep SAS Macros}

   Copy the file \Code{statrep\_macros.sas} to a local directory. If you have a
   folder where you keep your personal set of macros, copy the file
   there. Otherwise, create a directory such as
   \Code{C:\textbackslash{}mymacros} and copy the file into that directory.

\section{Step 2: Install the StatRep LaTeX Package}

   These instructions show how to install the StatRep package
   in your \LaTeX\ distribution for your personal use.

  \begin{enumerate}[a)]
   \item
   \textbf{Mik\TeX\ users}: If you do not have a directory for your own
   packages, choose a directory name to contain your packages
   (for example, c:\textbackslash{}localtexmf).

   In the following instructions, this directory is referred to as the
   "root directory".

   \textbf{\TeX{}Live users}:
   If you maintain a system-wide LaTeX distribution and you want to
      make StatRep available to all users, see more detailed information
      about how to install LaTeX packages at:
      \url{http://www.tex.ac.uk/cgi-bin/texfaq2html?label=what-TDS}

   Determine the location that LaTeX uses to load packages. At a
   command-line prompt, enter the following command:\\
   \texttt{kpsewhich -var-value=TEXMFHOME}

   The command returns the root directory name in which LaTeX can
   find your personally installed packages.

    In the following instructions, this directory is referred to as the
    "root directory".

   \item
   Create the directory if it does not exist, and create the additional
   subdirectories \Code{tex/latex/statrep}.
   Your directory tree will have the following structure:
\begin{verbatim}
      ---------------
      root directory/
         tex/
            latex/
              statrep/
\end{verbatim}
  \item
   Copy the files \Code{statrep.dtx}, \Code{statrep.ins}, \Code{statrepmanual.pdf},
   and \Code{statrepmanual.tex} to
   the \Code{statrep} subdirectory. Your directory tree will have the following structure:
\begin{verbatim}
      ---------------
      root directory/
         tex/
            latex/
                 statrep/
                       statrep.dtx
                       statrep.ins
                       statrepmanual.pdf
                       statrepmanual.tex
      ---------------
\end{verbatim}
   \item
   Change to the \Code{statrep} directory and enter the following command:\\
   \texttt{pdftex statrep.ins}

   The command creates several files, one of which is the configuration
   file, \Code{statrep.cfg}.

   \textbf{Mik\TeX\ users}:
   Add the root directory name from Step 2a according to these instructions
   for installing packages for MikTeX
   (\textit{Register a user-managed TEXMF directory}):
   \url{http://docs.miktex.org/manual/localadditions.html}

\end{enumerate}

\section{Step 3: Tell the StatRep Package the Location of the StatRep SAS Macros}

   Edit the \Code{statrep.cfg} file that was generated in Step 2d so that the macro
   \cs{SRmacropath} contains
   the correct location of the macro file from step 1. For example, if
   you copied the \Code{statrep\_macros.sas} file to a directory named
   \Code{C:\textbackslash{}mymacros},
   then you define macro \cs{SRmacropath} as follows:
   \begin{verbatim}
      \def\SRmacropath{c:/mymacros/statrep_macros.sas}
   \end{verbatim}

   Use the forward slash
   as the directory name delimiter instead of the backslash, which is a special
   character in LaTeX.

   You can now test and experiment with the package. Create a working
   directory, and copy the file \Code{quickstart.tex} into it.

   To generate the quick-start document:
\begin{enumerate}
\item Compile the document with pdf\LaTeX. You can use a \LaTeX-aware
      editor such as \TeX works, or use the command-line command \Code{pdflatex}.
      This step generates the SAS program that is needed to produce the results.

\item Execute the SAS program quickstart\_SR.sas, which was automatically
      created in the preceding step. This step generates the SAS
      results that are requested in the quick-start document.


\item Recompile the document with pdf\LaTeX. This step compiles the
      quick-start document to PDF, this time including the SAS results
      that were generated in the preceding step.

      In some cases listing outputs may not be framed properly after this step.
      If your listing outputs are not framed properly, repeat this step so that
      LaTeX can remeasure the listing outputs.

\end{enumerate}
   You can make changes to the file with a \LaTeX-aware editor
   or with any plain-text editor such as \textsf{NotePad} or \textsf{emacs}.

If you ever want to uninstall the \StatRep package,
delete the \Code{statrep} directory that you created
in the installation step 2d and remove the SAS macro file \Code{statrep\_macros.sas}
that you copied in installation step 1.
   Mik\TeX\ users must additionally update the filename database.\\
   \Code{(MikTeX Options dialog: General-> Refresh FNDB)}

\chapter{The \texttt{longfigure} Package}\label{longfigure}\index{longfigure package}


    The \Code{longfigure} package uses and relabels components of the
    well-known \Code{longtable} package, written by David Carlisle, to
    provide a table-like environment that can display a stream
    of subfigures as a single figure that can break across pages.

    The \Code{longtable} package defines a \Code{longtable} environment,
    which produces tables that can be broken by \TeX's standard page-breaking algorithm.
    Similarly, the \Code{longfigure} package defines a \Code{longfigure} environment, which produces
    figures that can be broken by \TeX's standard page-breaking algorithm.
    The internal structure of a long figure is similar to a long table.
    Rows might contain (for example) tables or graphics. Page breaks
    can occur only between rows.

     The \Code{longfigure} package differs from the \Code{longtable} package in the following ways:
    \begin{itemize}
      \item The \Code{longfigure} package supports two additional key-value options:
      \begin{itemize}
        \item The \Code{figname=} option specifies the counter for numbering
        \Code{longfigure} environments.
              You can specify any string; the default is \Code{figure}.
              When you specify a \Code{figname=} value for which no counter already exists, the
              \Code{longfigure} package loads the \Code{tocloft} package and creates the counter.
              \index{figname option}

       \item The \Code{resetby=} option specifies a counter (for example,
             \Code{resetby=chapter}) such
             that output numbering is reset each time the counter value changes.
             If a counter is specified that does not exist, the \Code{tocloft} package is
             loaded to create the new counter.
             \index{tocloft package}%
             For information about how the lists are typeset,
             \index{list of outputs, creating}%
             see the \Code{tocloft} package documentation.
      \end{itemize}
      \item The counters and macros that start with \cs{LT} in the \Code{longtable} package
            are renamed to start with \cs{LF} in the \Code{longfigure} pacakge to avoid
            namespace conflicts when the two packages are used together.
            The generic macros that are defined in the \Code{longtable} package
            (\cs{endfirsthead}, \cs{endhead}, \cs{endfoot}, and \cs{endlastfoot}) are
            also renamed with \cs{LF} as a prefix in the \Code{longfigure} package.

      \item The \cs{LF@name} macro is based on the \cs{fnum@table} macro from
            the \Code{longtable} package. The  \cs{LF@name} macro returns the capitalized
            counter name and value. For example, if the counter is \Code{figure} and the
            macro is processing the second \Code{longfigure}, the \cs{LF@name} macro
            would contain the value ``Figure 2.''

  \end{itemize}
    You can use the \Code{longfigure} package defaults to produce a \emph{List of Figures}
    by inserting the following tag in your document at the point where you want
    the list to appear:

\begin{verbatim}
  \listoffigures
\end{verbatim}


    The default counter used to display figures is the \Code{figure} counter,
    but you can specify a different counter. For example, if you want your
    figures to be labeled as ``Display,'' specify \Code{figname=display} when you
    load the \Code{longfigure} package; to display a \emph{List of Displays}, insert the following
    command in your document at the point where you want the list to appear:

\begin{verbatim}
  \listofdisplay
\end{verbatim}

    \textbf{Note:}  If you specify a counter that does not exist,
    an auxiliary file with extension \Code{.lft} is created to contain the information
    needed to create the list.

    If you want to use more advanced features of the \Code{tocloft} package,
    load it before you load the \Code{longfigure} package so that the \Code{longfigure}
    package sees that the counters specified by the \Code{figname=} and \Code{resetby=}
    options are already defined and does not attempt to create them.


\section{Example}
 The following lines produce a single figure that contains three images and
 one tabular environment. Each element is a row of the \Code{longfigure} environment.
 Page breaks can occur between rows.

\begin{verbatim}
\documentclass{book}
\usepackage{graphicx}
\usepackage{longfigure}

\begin{document}
  \begin{longfigure}{c}
    \caption{My Long Figure}\label{mlfig}\\
    \includegraphics[width=3in]{myfig1}\\
    \includegraphics[width=3in]{myfig2}\\
    \includegraphics[width=3in]{myfig3}\\
    \begin{tabular}{ll}
      one & two \\
      three & four\\
    \end{tabular}
  \end{longfigure}
\end{document}
\end{verbatim}

  In this example, the \Code{\{c\}} argument in the \cs{begin\{longfigure\}} command
  specifies only a single centered column. You can also specify multiple columns and,
  if needed, use the \cs{multicolumn} command for more flexibility.
%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%

\chapter{The ODS \StatRep LaTeX Tagset}\label{latexoutput}
\index{ODS LaTeX output}\index{LaTeX output}
The \StatRep package provides limited support for
SAS-generated LaTeX output\footnote{Since SAS 9.1, SAS\textsuperscript{\textregistered}
has provided an experimental LaTeX tagset.\index{statrep tagset}
The \texttt{statrep} tagset is a simplified version of that experimental tagset.}.

Three corresponding configuration variables are available. You can change them
in the file \texttt{statrep.cfg} or in your LaTeX document.
For complete details about the configuration file, see
the section \ref{custom}.

The variables are as follows:

\begin{itemize}
\item \cs{SRdefaultdests} specifies the type of ODS output to generate.
The default is \texttt{listing}, which corresponds to the ODS Listing destination.
\item \cs{SRlatexstyle} specifies the ODS style for SAS-generated LaTeX tables.
The default is \texttt{statrep}, which is a monochromatic style based on the
SAS ODS LaTeX tagset.
\item \cs{SRlatexdir} specifies the name of the subdirectory into which
SAS writes the LaTeX output files.
The default is \texttt{tex}.
\end{itemize}

To enable the use of LaTeX output in \StatRep, follow these steps.
\begin{enumerate}

\item Change your \StatRep configuration or in your LaTeX document.
The \cs{SRdefaultdests} setting
selects the default output type; it can have the value \texttt{latex}
or \texttt{listing}. The default value is \texttt{listing}.
You can change the value in the \texttt{statrep.cfg} configuration file as follows:

\begin{verbatim}
   \def\SRdefaultdests{latex}
\end{verbatim}

Alternatively, you can change the value in your LaTeX document
after the \StatRep package is loaded and before your document begins:

\begin{verbatim}
  \documentclass{article}
  \usepackage{statrep}
  \def\SRdefaultdests{latex}
  \begin{document}
\end{verbatim}

\item Run the included SAS program \Code{statrep\_tagsets.sas}\index{statrep tagset}
before you generate the SAS output for your document. This program creates
a \texttt{statrep} tagset  and a \texttt{statrep} ODS style.
When you run the program to generate the output for your document,
SAS must be able to find the \texttt{statrep} tagset in order to produce LaTeX
tabular output that is compatible with the \StatRep package.

For details on installing and storing tagsets see this SAS\textsuperscript{\textregistered} Note:
\url{http://support.sas.com/kb/32/394.html}

\end{enumerate}

\section{How It Works}

When you first compile your document with \texttt{pdflatex}, the SAS
program to produce the requested outputs is generated.

When you run the program, SAS checks the type of output requested,
which is controlled with the \cs{SRdefaultdests} setting.
If the output type is \texttt{latex},
LaTeX output is written to a subdirectory named \texttt{tex}.
If the output type is \texttt{listing},
ODS Listing output is  written to a subdirectory named \texttt{lst}.


When you recompile your document with \texttt{pdflatex}, the
\cs{Listing} tag displays the requested output objects,
insuring that your outputs are displayed properly with automatic page breaking.

\section{Customization}

\begin{description}
\item[ODS Style] You can specify an ODS style for your LaTeX output with the \cs{SRlatexstyle}
setting. The default is \texttt{statrep}, a monochrome style that is generated by the
SAS program \Code{statrep\_tagsets.sas}.\index{statrep tagset}
Examples of different styles are provided in the section \titleref{styleexamples}.

If you specify an ODS style that uses color, specify the \texttt{color} option
when you load the \StatRep package.

\begin{verbatim}
\documentclass{article}
\usepackage[color]{statrep}
\end{verbatim}

The style setting for LaTeX tables cannot be changed within a document.
That is, you cannot mix ODS LaTeX styles within a document.\index{mixing LaTeX styles}
If you change the style within your document, the last
style specified is used for all LaTeX outputs.

\item[Mixing Output Types] You can mix output types with the \texttt{dest=}
option on the \cs{Listing} tag.\index{mixing output types}
The option overrides the global \cs{SRdefaultdests} setting.

For example, if your \cs{SRdefaultdests} is set to \texttt{latex}, you can
specify that a particular \cs{Listing} output to be in listing format by
specifying \texttt{dest=listing} in the \cs{Listing} tag options, as follows:

\begin{verbatim}
\Listing[store=mydoc, dest=listing, caption={Results}]{outa}
\end{verbatim}

\item[Output Directory Name] You can change the name of the directory into which
SAS writes the outputs with the \cs{SRlatexdir} variable. The default
subdirectory name is \Code{tex}.

\end{description}

\section{Caution}

In some cases the LaTeX tagset produces tables that are too wide
to fit in the text block. In some cases, you can shift the table to
the left so the table will fit on the page. You can shift the table
with the \cs{LFleft} command.

The following example moves the left margin of the
output 1 inch to the left of its normal location
(the start of the text block).
The output is then typeset and the margin is set back to its default value of 0.

\begin{verbatim}
   \LFleft=-1in
   \Listing[store=mydoc, caption={Results}]{outa}
   \LFleft=0in
\end{verbatim}

In some cases, the table will not fit on the page at all.
The only solution in those cases is to change back to the
\texttt{listing} output destination, modifying the fontsize and linesize
as needed.

Some ODS styles may not work with the LaTeX tagset. For example,
some styles specify fonts that are available to SAS but not to LaTeX.

\section{Style Examples}\label{styleexamples}

\begin{figure}[H]
\caption{Listing Output}
\includegraphics{images/listing}
\end{figure}
\begin{figure}[H]
\caption{LaTeX Output, default style}
\includegraphics{images/default}
\end{figure}
\begin{figure}[H]
\caption{LaTeX Output, \texttt{statistical} style}
\includegraphics{images/statistical}
\end{figure}
\begin{figure}[H]
\caption{LaTeX Output, \texttt{journal} style}
\includegraphics{images/journal}
\end{figure}
\begin{figure}[H]
\caption{LaTeX Output, \texttt{htmlblue} style}
\includegraphics{images/htmlblue}
\end{figure}


\chapter{\StatRep with SAS Studio or SAS University Edition}\label{sasstudio}
\index{SAS Studio}\index{University Edition}\index{SAS University Edition}
\index{web interface}

You can use \StatRep with the SAS Studio web-based interface and SAS University Edition.
You can find more information on these applications here:
\begin{description}
\item[SAS Studio] is a web application for SAS that you access through your web browser.
\url{http://support.sas.com/software/products/sasstudio/}

\item[SAS University Edition]
is free and includes the SAS products Base SAS, SAS/STAT, SAS/IML, SAS/ACCESS Interface to PC Files, and SAS Studio.
\url{http://support.sas.com/software/products/university-edition/index.html}
\end{description}

With a web interface, there is no concept of a \emph{current directory},
so you must let SAS know where your files are located.
In order to use \StatRep, SAS needs to know the following locations:

\begin{itemize}
\item the directory that contains your LaTeX file.
\item the full path to the file \texttt{statrep\_macros.sas}.
\item the location of the \StatRep ODS tagset, if you prefer LaTeX output (instead of Listing output).
See the previous chapter for details on how to create and use this tagset.
\end{itemize}

With SAS University Edition, you run a virtual machine on your local computer so you can
create a shared folder that SAS can access.\index{virtual machine}
For SAS Studio folder locations, see the following section for details.

\section{SAS Studio Folders}
\index{SAS Studio}
Other than SAS University Edition, there are three 3 types of installations for SAS Studio:
\begin{itemize}
\item SAS Studio Single User
\item SAS Studio Basic (Windows or UNIX)
\item SAS Studio Mid-Tier (Enterprise Edition)
\end{itemize}

For Single User, \textit{My Folders} is your home directory on your local machine and the folders list will also include folders for your desktop, documents folder, and mapped drives.

For both Enterprise and Basic edition, the path for \textit{My Folders} is the home directory on the remote SAS server.  That is, the file system in the \textit{Folders} accordion is not your local machine;
it is the location of the remote server.

On Windows, you can add a \textit{Folder Shortcut} back to your local computer.
The shortcut must be accessible by the remote server.
On UNIX, you can add a \textit{Folder Shortcut} to your home directory.

You may need to ask your local SAS administrator about how to create a folder shortcut to your local
files.

\section{SAS University Edition: Creating a Shared Folder}
\index{University Edition}\index{SAS University Edition}\index{virtual machine}
Suppose you have a directory called \texttt{mydocs} that contains your LaTeX file.
You create a shared folder in the virtual machine as shown in the following screenshot:

\includegraphics[width=\textwidth]{images/vm1}

When you select \texttt{Shared Folders} and click to add a new path,
enter the information (path and name) as shown in the following screenshot:

\includegraphics[width=\textwidth]{images/vm2}

The \texttt{Folder Path} is the absolute path to the directory and the
folder name is the last part of that path.
The name is a short-hand name that is used later in your code.
Make sure to select \texttt{Auto-mount} if you want to use the folder in later SAS sessions (as you probably will).
The result of entering the information is shown in the following screenshot.

\includegraphics[width=\textwidth]{images/vm3}

When you start SAS Studio, the \texttt{Folder} panel shows your new shared folder as a \emph{Folder Shortcut}.
SAS will know this folder by the full name \texttt{/folders/myshortcuts/mydocs},
which means you can use that name to assign filerefs and libnames as you normally would in any SAS program.

Notice the \texttt{Folder} panel in the following screenshot.
You can disregard most of the code in the program editor window,
but do notice the first line that references the new shared folder.

\includegraphics[width=\textwidth]{images/sasuniv1}

The LIBNAME statement in the code window assigns the \texttt{mytempl} libref to your shared folder.

\section{The Bridge Between LaTeX and SAS}

Now you have your working directory and SAS knows that there is such a location.
The final step is to define a bridge between your LaTeX document and SAS.

You connect the two by defining a LaTeX tag called \verb+\SRrootdir+, which contains the
path to your shared folder as displayed in the following LaTeX code:

\begin{verbatim}
    \documentclass{article}
    \usepackage[margin=1in]{geometry}
    \usepackage[color]{statrep}
    \def\SRrootdir{/folders/myshortcuts/mydocs}
    \def\SRmacropath{/folders/myshortcuts/mydocs/statrep_macros.sas}
    \begin{document}
\end{verbatim}

This document preamble performs the following:
\begin{itemize}
\item  Specifies that the document use the \texttt{article} class.
\item  Loads the \texttt{geometry} package and specifies 1 inch margins on all sides.
\item  Loads the \texttt{statrep} package and specifies that outputs can include color.
\item  Defines the \verb+\SRrootdir+ path (the path to the working directory) as the shared folder you created in the previous steps.
\item  Defines the \verb+\SRmacropath+ that contains the full path and file name of the \texttt{statrep\_macros.sas} file
that is part of the \StatRep package.
This example shows that it is in the same directory as the LaTeX file, but you can put the macros anywhere you like,
as long as SAS can find the file (that is, as long as the macros are in a shared folder)
\end{itemize}

With this preamble, you can start writing your content; when \StatRep automatically generates the SAS program to create your output,
the paths you have defined here are used so SAS can find the macros it needs and so it can write the requested outputs to your working directory.

From this point on, you use \StatRep just as you would normally.


\printindex
\end{document}