PROC DOCUMENT is one of the niftier tools in SAS. To get the most benefit out of it, you need to create a workflow that makes saving your work to the document effortless. This post discusses some things that can help you get more out of PROC DOCUMENT. It will show you how to direct your work to folders. To see many other ways the ODS DOCUMENT can make your life easier, take a look at my book PROC DOCUMENT by Example Using SAS.
Have you ever had the situation where your work requires you to run several analyses, each different in some minor way? PROC DOCUMENT can make it easy for you to organize such work by directing the output to folders as the SAS code runs.
To make using the document nearly effortless, use an abbreviation, or a shortcut key in your favorite text editor to put the following lines at the beginning of your code and ODS DOCUMENT CLOSE; at the end.
ods document name=_________._________ dir=(path=_____________ label= ); /* your code goes here */ ods document close;
The code for today's example comes from SAS for Mixed Models, Second Edition, by Ramon Littell, George Milliken, Walter Stroup, Russell Wolfinger, and Oliver Schabenberger. It's not necessary to understand the statistics; just that each variation of the procedure is saved to its own folder.
The first code sample illustrates how, if you repeatedly run similar analyses off the same source code, you can still keep your output well organized when you save each run to its on folder in an ODS DOCUMENT.
ods document name=sasuser.mmodel(write) /* start a document */ dir=(path=\Type3 label='Outputs 2.1 and 2.2, using the Analysis of Variance Method' ); /* specify a starting folder */ proc mixed data=bond covtest cl method=type3; class ingot metal; model pres = metal / ddfm=kr; random ingot; run; /* you can change folders midstream */ ods document dir=(path=\reml label='Output 2.3, using the REML method' ); proc mixed data=bond method=reml; class ingot metal; model pres=metal; random ingot; run; ods document close;
With the work saved, you can print it out again to any destination and in any order - all without re-running the original analysis. Furthermore, with PROC DOCUMENT's WHERE= option on Document Paths, you can swiftly perform analyses that require output from multiple folders. Code sample 2 shows how you might use the document created in Code sample 1.
proc document name=sasuser.mmodel; obbnote \reml#1\mixed\tests3 'REML Method'; obbnote \type3#1\mixed\tests3 'Analysis of Variance Method'; replay reml; /* only the reml stuff */ replay ^(where=(_name_ = 'Tests3')) / activetitle ; replay same; /* Compare */ quit;
The OBBNOTE statements give the output a little extra annotation in addition to SAS Titles. The screen shots show the output of the LIST and the second REPLAY statement. According to SAS for Mixed Models, Second Edition it’s intended that the two Fit Statistics be identical. Adding this habit into your work does two things; it documents your source code and it documents your output at the same time, making it easy to find the most relevant analysis in a pinch.