24.5 - Tracing and Selecting Procedure Output

As discussed earlier, when ODS receives data from a procedure, it combines the data component with a table definition to create an output object. For many procedures, ODS creates just one output object, while for others it produces several. Procedures involving a BY statement, for example, typically produce an output object for each BY group. When a procedure does create more than one output object, you might not want SAS to include all of them in your output. You might instead want to tell SAS to select just one or two of the output objects. In this section, we learn how to use the ODS TRACE and ODS SELECT statements to choose the specific output objects that you want SAS to display in your output.

The ODS TRACE ON statement tells SAS to print information in the log about the output objects created by all of the code in your program between the ODS TRACE ON statement and a closing ODS TRACE OFF statement.

Example 24.7 Section

The following program uses ODS TRACE statements to capture information about the output objects created by the MEANS procedure on a data set called golfbypar, which is just a sorted version of the penngolf data set:

PROC SORT data = stat481.penngolf out = golfbypar;
    by par;
RUN;
 
ODS TRACE ON;
PROC MEANS data = golfbypar;
    by par;
    title 'Pennsylvania Golf Courses by Par';
RUN;
ODS TRACE OFF;

Pennsylvania Golf Courses by Par

The MEANS Procedure

Par=70
VariableNMeanStd DevMinimumMaximum
ID3108.33333332.0816660106.0000000110.0000000
Year31966.336.50640711960.001973.00
Yards36283.33295.66929726004.006593.00
Slope3126.00000006.0000000120.0000000132.0000000
USGA370.23333331.069267769.300000071.4000000
Par=71
VariableNMeanStd DevMinimumMaximum
ID3105.33333332.5166115103.0000000108.0000000
Year31934.3334.01960221909.001973.00
Yards36416.6763.68935026369.006489.00
Slope3127.33333334.0414519123.0000000131.0000000
USGA371.33333330.513160170.900000071.9000000
PAR=72
VariableNMeanStd DevMinimumMaximum
ID5105.00000004.0620192101.0000000111.0000000
Year41957.0024.09702611921.001972.00
Yards56840.00235.55466466525.007123.00
Slope5131.80000005.7619441125.0000000140.0000000
USGA573.26000001.083051272.000000074.3000000

The SORT procedure, of course, just sorts the permanent data set stat481.penngolf by par and stores the sorted result in a temporary data set called golfbypar. Then, the ODS TRACE ON statement tells SAS to start capturing information about any output objects that are created. The MEANS procedure tells SAS to summarize the golfbypar data set for each level of par, that is when par equals 70, 71, and 72. Finally, the ODS TRACE OFF statement tells SAS to stop capturing information about any output objects that are created.

Launch and run  the SAS program. You can go ahead and review the output from the MEANS procedure, but what we're really interested in here is the information SAS displays about the output objects in the log window:


   ODS TRACE ON;
   PROC MEANS data = golfbypar;
       by par;
       title 'Pennsylvania Golf Courses by Par';
   RUN;
NOTE: Writing HTML Body file: sashtml.htm
Output Added:
-------------
Name:       Summary
Label:      Summary statistics
Template:   base.summary
Path:       Means.ByGroup1.Summary
-------------
NOTE: The above message was for the following BY group:
      Par=70
Output Added:
-------------
Name:       Summary
Label:      Summary statistics
Template:   base.summary
Path:       Means.ByGroup2.Summary
-------------
NOTE: The above message was for the following BY group:
      Par=71
Output Added:
-------------
Name:       Summary
Label:      Summary statistics
Template:   base.summary
Path:       Means.ByGroup3.Summary
-------------
NOTE: The above message was for the following BY group:
      Par=72
NOTE: There were 11 observations read from the data set WORK.GOLFBYPAR.
NOTE: PROCEDURE MEANS used (Total process time):
      real time           0.70 seconds
      cpu time            0.39 seconds
   ODS TRACE OFF;

As the log suggests, the MEANS procedure creates one output object for each BY group (par = 70, par = 71, and par = 72). The three output objects share the same name, label, and template, but different paths. The path for the par = 70 output object, for example, is called Means.ByGroup1.Summary and the path for the par = 71 output object is called Means.ByGroup2.Summary. Once we know the names of the output objects, we can use an ODS SELECT statement to tell SAS the specific output objects that we want to be displayed. To select specific output objects, simply place an ODS SELECT statement within the relevant procedure. By default, the ODS SELECT statement lasts only for the procedure in which it is contained.

Example 24.8 Section

The following program uses an ODS SELECT statement and what we learned from tracing our MEANS procedure to print just the portion of the output that pertains to the par 70 golf courses:

PROC MEANS data = golfbypar;
    by par;
    title 'Par 70 Golf Courses';
    ODS SELECT Means.ByGroup1.Summary;
RUN;

Par 70 Golf Courses

The MEANS Procedure

Par=70
VariableNMeanStd DevMinimumMaximum
ID3108.33333332.0816660106.0000000110.0000000
Year31966.336.50640711960.001973.00
Yards36283.33295.66929726004.006593.00
Slope3126.00000006.0000000120.0000000132.0000000
USGA370.23333331.069267769.300000071.4000000

Launch and run  the SAS program, and review the output to convince yourself that SAS displays only the portion of the MEANS procedure that pertains to the par 70 golf courses.