Advanced Features of the DOCUMENT Procedure

Overview

In Creating an ODS Document, you learned how to manipulate output objects using the Documents window. You can use PROC DOCUMENT statements to accomplish all of the tasks that you completed using the Documents window and much more. For complete documentation on the DOCUMENT procedure, see The DOCUMENT Procedure in SAS Output Delivery System: User's Guide.
The combination of the ODS DOCUMENT statement and the DOCUMENT procedure enables you to store a report’s individual components. You can then modify and replay the report. The ODS DOCUMENT statement stores the actual ODS objects that are created when you run a report. You can use the DOCUMENT procedure to rearrange, duplicate, or remove output from the results of a procedure or a database query without invoking the procedure or database query from the original report. You can use the DOCUMENT procedure to do the following:
  • Transform a report without rerunning an analysis or repeating a database query.
  • Modify the structure of the output.
  • Display output to any ODS output format.
  • Navigate the current directory and list entries.
  • Open and list ODS documents.
  • Manage output.
With the DOCUMENT procedure, you are not limited to regenerating the same report. You can change the order in which objects are rendered, the table of contents, the templates that are used, macro variables, and ODS and system options.

Working with the DOCUMENT Procedure

To create an ODS document, you can use the Documents window or the ODS DOCUMENT Statement in SAS Output Delivery System: User's Guide. The following code creates the ODS document Work.Prddoc within a document store:
ods listing close;
proc sort data=sashelp.prdsale out=prdsale;
    by Country;
run;

ods document name=work.prddoc(write);

proc tabulate data=prdsale;
    by Country;
    var predict;
    class prodtype;
    table prodtype all,
    predict*(min mean max);
run;

ods select ExtremeObs;

proc univariate data=prdsale;
    by Country;
    var actual;
run;

ods document close;
The following display shows the ODS document Work.Prddoc and its contents. To view the Documents window, submit the following command on the command line: odsdocuments
SAS Documents Window Showing Work.Prddoc Document and Documents Icon
SAS Documents Window Showing Work.Prddoc Document and Documents Icon
The following display shows the properties of Table 1. You can see the document name and the document path, as well as other information.
Table Properties for Table 1
Table Properties for Table 1
An ODS document store is not a SAS data set, as you can see by the Document icon in the previous display. The Work.Prddoc document was written to the Work library. If it had been written to a permanent location (such as c:\temp\output), in Windows Explorer, the document store would have a file extension of SAS7BITM.
After you have created a document with the ODS DOCUMENT statement, you can use the LIST statement in a PROC DOCUMENT step to view the contents of your document. The LIST statement enables you to look at the object list and folder structure in the ODS document. The following code creates a list of all levels of the Work.Prddoc document:
proc document name=work.prddoc; 
    list / levels=all; 
run; 
quit;
The LIST statement can list what is in an entire document or in just one of the entries. For more information about the LIST statement, see The DOCUMENT Procedure in SAS Output Delivery System: User's Guide.
In the following figure, every folder icon in the Results window corresponds to an item with a type of Dir in the LIST statement output. Every table created by a procedure corresponds to an item with a type of Table in the LIST statement output.
PROC DOCUMENT List Statement Output Compared to Results Window
PROC DOCUMENT List Statement Output Compared to Results Window