The DOCUMENT Procedure

Concepts: DOCUMENT Procedure

About ODS Documents

Overview

An ODS document is a hierarchical file of output objects that is created from a procedure or data query. The ODS document holds these output objects in their original structures, but you can rearrange the hierarchy and structure of these objects. ODS documents are stored in a proprietary format (a document store) and can be viewed only with SAS software. To view or modify what is in the document store, you must use either the Documents window or the DOCUMENT procedure.
To create an ODS document, you must use the ODS DOCUMENT Statement. 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 document Work.Prddoc and its contents. To view the Documents window, submit this command in the command bar: odsdocuments
SAS Documents Window Showing Document and Documents Icon
SAS Documents Window Showing Document and Documents Icon
The following display shows the properties of Table 1. You can see the document name and the document path, among 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 preceding display. This ODS document was written to the Work library. However, if it had been written to a permanent location (such as c:\temp\output), you would see in Windows Explorer that the document store has a file extension of SAS7BITM.

Items Included in an ODS Document

In an ODS document, each level of the hierarchical file represents a path that refers to the location of a file, link, or output object. An output object can be one of the following:
  • table
  • graph
  • equation
  • note
  • SAS/GRAPH external graph titles

Items Not Included in an ODS Document

An ODS document does not store the following items:
  • SAS logs
  • SAS system options
  • procedure options
  • ODS options
  • SAS/GRAPH options
  • GRSEGs (References to GRSEGs, but not GRSEGs themselves, are stored.)

ODS Document Persistence

An ODS document persists in the SAS system until the document, or the SAS library containing the document, is deleted. An ODS document that was created in the Sasuser library, or in another permanent SAS library, can persist indefinitely. It is considered a permanent archive of SAS procedure output. However, an ODS document that is created in the Work library does not persist longer than the SAS session that created it. For information about SAS libraries, see SAS Language Reference: Concepts.

Viewing the Contents of an ODS Document

After you have created a document with the ODS DOCUMENT statement, you can use PROC DOCUMENT to view the contents of your document. You can rearrange, duplicate, or remove output from the results of a procedure or a database query without invoking the procedures from the original report. The first step is to view your document’s contents by using the LIST statement. The LIST statement enables you to look at the object list and folder structure within the ODS document. The following code creates a list of all levels of the document Work.Prddoc:
proc document name=work.prddoc; 
    list / levels=all; 
run; 
quit;
The LIST statement can be used to list what is in an entire document or just one of the entries. For more information about the LIST statement, see LIST Statement.
In the following display, 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 Output Compared to Results Window
PROC DOCUMENT List Output Compared to Results Window

Understanding an ODS Document Path

Definition of ODS Document Path

An ODS document is stored as an item store. This file format enables client applications to define a hierarchical file system within a file. This is similar to a directory system in a UNIX or Windows operating environment. Therefore, an ODS document path indicates the location of an entry. In the preceding output, the document path for the entry Country=Canada is \Tabulate#1.

Entry Names

Entry names follow these rules:
  • must be alphanumeric
  • must begin with an alphabetical character
  • can contain underscores
  • can have no more than 32 characters
  • are preserved with casing that is specified in the operating environment
  • can have labels that are no more than 256 characters
Entries in an ODS document can be displayed in the following three ways:
  • ordered by insertion, which is the default order
  • ordered by ascending date-and-time stamp
  • ordered alphabetically

Understanding Sequence Numbers

Entry names are not required to be unique within an ODS document. However, they are uniquely identifiable because they contain sequence numbers. Every entry in an ODS document, except for the root directory, has a sequence number. A sequence number is a positive integer that is unique with respect to the name of the entry within the same directory. Entries are assigned sequence numbers according to the sequence in which they are added to a directory. For example, the first entry myname is assigned a sequence number 1, myname#1. The second entry myname is assigned a sequence number 2, myname#2. Sequence numbers are never reassigned, unless all entries with the same name are deleted. In this case, the sequence numbers are reset to have an initial number of 1.

ODS Documents and Base SAS Procedures

You can create an ODS document from almost any Base SAS procedure. The PRINT, REPORT, and TABULATE procedures use table templates that are created by the user and not defined by an external template in ODS. These procedures use custom table templates, custom data components, and custom formats for their output objects. Nevertheless, the ODS document and all of its features are supported for the PRINT, TABULATE, and REPORT procedures.

Getting Familiar with Output Objects

An output object is one of the following:
  • equation
  • graph
  • note
  • table
Output objects have associated information and attributes. Some or all of the following attributes pertain to output objects:
after-note
is the note assigned to the output object by the procedure that produced the object. This note is displayed every time the output object is displayed. After-notes display after the output object.
before-note
is the note assigned to the output object by the procedure that produced the object. This note is displayed every time the output object is displayed. Before-notes display before the output object.
footnote
is created by the FOOTNOTE statement and is displayed at the bottom of the page.
page break
causes a page break before displaying the output object and any associated titles and notes.
subtitle
is the title that is assigned to the output object by the procedure that produced the output object. This title is displayed every time a new page of output is started.
title
is created by the TITLE statement and is displayed at the bottom of the page.
Here is the order in which the attributes of an output object are displayed:
  1. page break
  2. titles
  3. subtitles
  4. before-notes
  5. output object
  6. after-notes
  7. footnotes

Understanding How ODS Documents Interact across Operating Environments

Compatibility across SAS Versions

An ODS document that is created in the current version of SAS is compatible with later versions of SAS. In most cases, an ODS document created in a later version of SAS will still be compatible with an earlier version of SAS.
ODS documents are not portable across operating environments. For example, an ODS document created in a Windows operating environment cannot be used in a mainframe operating environment.