Previous Page | Next Page

Using the Output Delivery System

Paths and Selection

You use the ODS statement to provide instructions to ODS. You can use ODS statements to specify options for different destinations, specify the output style, and select and exclude output. Here are some examples:

   /* open the HTML destination with the statistical style */
   ods html style=Statistical;
   
   /* select only the parameter estimates table */
   ods select ParameterEstimates;
   
   /* output the parameter estimates table to a SAS data set*/
   ods output ParameterEstimates=Parms;
   
   /* exclude the number of observations, ANOVA, and fit statistics tables */
   ods exclude NObs ANOVA FitStatistics;

In order to select, exclude, or modify a table, you must first know its name. You can obtain the table names in several ways:

  • You can obtain table names from the individual procedure chapter or from the individual procedure section of the SAS online Help system. See the "ODS Table Names" section within the "Details" section of the procedure documentation chapter.

  • You can use the SAS Results window to view the names of the tables created in your SAS session (see the section ODS and the SAS Results Window for more information).

  • You can use the ODS TRACE statement to find the names of tables created in your SAS session. The ODS TRACE statement writes identifying information to the SAS log or listing for each generated output table.

If you are working interactively with reasonably small data sets, then the ODS TRACE statement is usually the most convenient way to find the names. Specify the ODS TRACE ON statement prior to the procedure statements that create the output for which you want information. For example, the following statements write the trace record for the specific tables created in the REG procedure step:

   ods trace on;
   proc reg;
      model y=x;
      model z=x;
   run;
   ods trace off;

By default, the trace record is written to the SAS log. The output from this step is as follows:

   Output Added:
   -------------
   Name:       NObs
   Label:      Number of Observations
   Template:   Stat.Reg.NObs
   Path:       Reg.MODEL1.Fit.y.NObs
   -------------

   Output Added:
   -------------
   Name:       ANOVA
   Label:      Analysis of Variance
   Template:   Stat.REG.ANOVA
   Path:       Reg.MODEL1.Fit.y.ANOVA
   -------------

   Output Added:
   -------------
   Name:       FitStatistics
   Label:      Fit Statistics
   Template:   Stat.REG.FitStatistics
   Path:       Reg.MODEL1.Fit.y.FitStatistics
   -------------

   Output Added:
   -------------
   Name:       ParameterEstimates
   Label:      Parameter Estimates
   Template:   Stat.REG.ParameterEstimates
   Path:       Reg.MODEL1.Fit.y.ParameterEstimates
   -------------

   Output Added:
   -------------
   Name:       NObs
   Label:      Number of Observations
   Template:   Stat.Reg.NObs
   Path:       Reg.MODEL2.Fit.z.NObs
   -------------

   Output Added:
   -------------
   Name:       ANOVA
   Label:      Analysis of Variance
   Template:   Stat.REG.ANOVA
   Path:       Reg.MODEL2.Fit.z.ANOVA
   -------------

   Output Added:
   -------------
   Name:       FitStatistics
   Label:      Fit Statistics
   Template:   Stat.REG.FitStatistics
   Path:       Reg.MODEL2.Fit.z.FitStatistics
   -------------

   Output Added:
   -------------
   Name:       ParameterEstimates
   Label:      Parameter Estimates
   Template:   Stat.REG.ParameterEstimates
   Path:       Reg.MODEL2.Fit.z.ParameterEstimates
   -------------

Alternatively, you can specify the LISTING option (ods trace on / listing;), which writes the trace record, interleaved with the procedure output, to the LISTING destination.

The trace record contains the name of each created table and its associated label, template, and path. The label provides a description of the table. The path shows the output hierarchy for the table (see, for example, Figure 20.2). In this example, the hierarchy has a level for the REG procedure, a level for the model (MODEL1 or MODEL2), a level for the fit results, a level for the dependent variable (y or z), and a level for the table name (NObs, ANOVA, FitStatistics, ParameterEstimates, NObs, ANOVA, FitStatistics, ParameterEstimates). The path shown in the trace record is fully qualified. Often, you can omit levels and instead use a partially qualified path. A partially qualified path consists of any part of the full path that begins immediately after a period and continues to the end of the full path. For example, the full path for the parameter estimates for the first model in the preceding regression analysis is Reg.Model1.Fit.y.ParameterEstimates. This table can be referenced in any of the following ways:

ParameterEstimates

name

y.ParameterEstimates

partially qualified path

fit.y.ParameterEstimates

partially qualified path

Model1.fit.y.ParameterEstimates

partially qualified path

Reg.Model1.fit.y.ParameterEstimates

fully qualified path

When a procedure creates multiple tables that have the same name, as in the preceding example, you have several selection options. You can specify the name, a full path, or a partially qualified path when you refer to a table (for example, when you select it or exclude it from display). You can also specify a WHERE clause. For example, you can specify any of the following statements to display both tables of parameter estimates:

   ods select ParameterEstimates;
   
   ods select y.ParameterEstimates z.ParameterEstimates;
   
   ods select Reg.Model1.Fit.y.ParameterEstimates
              Reg.Model2.Fit.z.ParameterEstimates;
   
   ods select where = (_path_ ? 'Parameter');

There are other possibilities as well. The first ODS SELECT statement specifies the single name, which is shared by both tables. The second statement specifies a partially qualified path for both tables. The third statement specifies the full path for both tables. The fourth statement selects every object (table or graph) that contains the string Parameter anywhere in its path. Note that in the first three statements, selection is case insensitive. Any combination of uppercase and lowercase letters will work. This is not true in the fourth statement, which uses an ordinary SAS comparison of character strings. The following WHERE clause selection is case insensitive:

   ods select where = (lowcase(_path_) ? 'parameter');

You can also select objects based on a WHERE clause and the label path. The following statements turn on the trace record, display a label path in addition to the name path, and select all tables that have the string 'var' in the label:

   ods trace on / label;
   ods select where = (lowcase(_label_) ? 'var');


A subset of the trace record for PROC REG with this select list, showing just the name and label paths, is as follows:

Path:       Reg.MODEL1.Fit.y.ANOVA
Label Path: 'The Reg Procedure'.'MODEL1'.'Fit'.y.'Analysis of Variance'
Path:       Reg.MODEL2.Fit.z.ANOVA
Label Path: 'The Reg Procedure'.'MODEL2'.'Fit'.z.'Analysis of Variance'

The ODS SELECT statement selects the ANOVA tables, because they have the string 'Analysis of Variance' (which when lowercased contains 'var') in their labels. WHERE clause selection is also useful for selecting all of the objects within a group or level of the path hierarchy (the group 'MODEL2' or 'Fit'). You can specify any part of the path or label path—for example, '.z.', the variable z ignoring any 'z' that might be in the middle of a word; '2.F', model 2 fit tables and any other table that has the string '2.F' in its path; and so on.

ODS records the specified table names in its internal selection or exclusion list, and then it processes the output it receives. Note that ODS maintains an overall selection or exclusion list that pertains to all ODS destinations, and it maintains a separate selection or exclusion list for each ODS destination. The list for a specific destination provides the primary filtering step. The restrictions that you specify in the overall list are added to the destination-specific lists.

Suppose, for example, that your LISTING exclusion list (that is, the list of tables you want to exclude from the LISTING destination) contains the FitStatistics table, which you specify with the following statement:

   ods listing exclude FitStatistics;

Suppose also that your overall selection list (that is, the list of tables you want to select for all destinations) contains the tables ParameterEstimates and FitStatistics, which you specify with the following statement:

   ods select ParameterEstimates FitStatistics;

ODS then sends only the ParameterEstimates and FitStatistics tables to all open destinations except the LISTING destination. It sends only the ParameterEstimates table to the LISTING destination because the table FitStatistics is excluded from that destination.

Some SAS procedures, such as PROC REG and PROC GLM, support RUN-group processing, which means that a RUN statement does not end the procedure. A QUIT statement explicitly ends such procedures. If you omit the QUIT statement, a PROC or a DATA statement implicitly ends such procedures. When you use ODS with procedures that support RUN-group processing, it is good programming practice to specify a QUIT statement at the end of the procedure. This causes ODS to clear the selection or exclusion list, and you are less likely to encounter unexpected results.


Previous Page | Next Page | Top of Page