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
Variable | N | Mean | Std Dev | Minimum | Maximum |
---|---|---|---|---|---|
ID | 3 | 108.3333333 | 2.0816660 | 106.0000000 | 110.0000000 |
Year | 3 | 1966.33 | 6.5064071 | 1960.00 | 1973.00 |
Yards | 3 | 6283.33 | 295.6692972 | 6004.00 | 6593.00 |
Slope | 3 | 126.0000000 | 6.0000000 | 120.0000000 | 132.0000000 |
USGA | 3 | 70.2333333 | 1.0692677 | 69.3000000 | 71.4000000 |
Variable | N | Mean | Std Dev | Minimum | Maximum |
---|---|---|---|---|---|
ID | 3 | 105.3333333 | 2.5166115 | 103.0000000 | 108.0000000 |
Year | 3 | 1934.33 | 34.0196022 | 1909.00 | 1973.00 |
Yards | 3 | 6416.67 | 63.6893502 | 6369.00 | 6489.00 |
Slope | 3 | 127.3333333 | 4.0414519 | 123.0000000 | 131.0000000 |
USGA | 3 | 71.3333333 | 0.5131601 | 70.9000000 | 71.9000000 |
Variable | N | Mean | Std Dev | Minimum | Maximum |
---|---|---|---|---|---|
ID | 5 | 105.0000000 | 4.0620192 | 101.0000000 | 111.0000000 |
Year | 4 | 1957.00 | 24.0970261 | 1921.00 | 1972.00 |
Yards | 5 | 6840.00 | 235.5546646 | 6525.00 | 7123.00 |
Slope | 5 | 131.8000000 | 5.7619441 | 125.0000000 | 140.0000000 |
USGA | 5 | 73.2600000 | 1.0830512 | 72.0000000 | 74.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
Variable | N | Mean | Std Dev | Minimum | Maximum |
---|---|---|---|---|---|
ID | 3 | 108.3333333 | 2.0816660 | 106.0000000 | 110.0000000 |
Year | 3 | 1966.33 | 6.5064071 | 1960.00 | 1973.00 |
Yards | 3 | 6283.33 | 295.6692972 | 6004.00 | 6593.00 |
Slope | 3 | 126.0000000 | 6.0000000 | 120.0000000 | 132.0000000 |
USGA | 3 | 70.2333333 | 1.0692677 | 69.3000000 | 71.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.