Using the Output Delivery System

Example 20.6 RUN-Group Processing

Some SAS procedures, such as PROC REG and PROC GLM, are interactive. They enable you to submit a group of statements that end with a RUN statement, and then submit more statement groups, each of which ends with a RUN statement. Each group of statements with its RUN statement is called a RUN group. For example, the following PROC REG step has two RUN groups:

proc reg data=sashelp.class;
   var Age;
   model Weight = Height;
run;

   model Weight = Height Age;
run;
quit;

Interactive procedures can produce several blocks of output for each of several RUN groups. The procedure stays active until it processes a QUIT statement, it encounters a DATA or PROC statement, or the SAS session ends. However, ODS settings are cleared by default at RUN-group boundaries. You can specify the PERSIST= option to maintain ODS settings across RUN statements for procedures that support RUN-group processing.

Consider a data set that contains US population growth trends:

title1 'US Population Study';
title2 'Concatenating Two Tables into One Data Set';

data USPopulation;
   input Population @@;
   retain Year 1780;
   Year=Year+10;
   YearSq=Year*Year;
   Population=Population/1000;
   datalines;
3929 5308 7239 9638 12866 17069 23191 31443 39818 50155
62947 75994 91972 105710 122775 131669 151325 179323 203211
;

In the following analysis, which has two RUN groups, PROC REG is used to compute the covariance matrix of the estimates for two different models, and the covariance matrices are saved in a single SAS data set. The PERSIST=RUN option in the ODS OUTPUT statement is required to make this happen. The first RUN group creates a data set that contains the CovB table (the covariance matrix of the estimates):

proc reg data=USPopulation;
   ods output covb(persist=run)=Bmatrix;
   var YearSq;
   model Population = Year / covb;
run;

The MODEL statement defines the regression model and requests the CovB table. The RUN statement executes PROC REG and the model is fit, producing a covariance matrix of the estimates. The covariance matrix has two rows and two columns and is shown in Output 20.6.1.

Output 20.6.1: CovB Table for the First Model

US Population Study
Concatenating Two Tables into One Data Set

The REG Procedure
Model: MODEL1
Dependent Variable: Population

Covariance of Estimates
Variable Intercept Year
Intercept 20393.138485 -10.83821461
Year -10.83821461 0.0057650078



In the next RUN group, the YearSq variable is added to the model and the model is fit again, producing a covariance matrix of the estimates that has three rows and three columns:

   add YearSq;
   print;
run; quit;

The CovB table for the second RUN group is displayed in Output 20.6.2.

Output 20.6.2: CovB Table for the Second Model

Covariance of Estimates
Variable Intercept Year YearSq
Intercept 711450.62602 -757.2493826 0.2013282694
Year -757.2493826 0.8061328943 -0.000214361
YearSq 0.2013282694 -0.000214361 5.7010894E-8



If the PERSIST=RUN option is omitted, the selection list is cleared when the RUN statement is encountered, and only the first CovB table is selected. But because the PERSIST=RUN option is specified, the selection list remains in effect throughout the PROC REG step. This ensures that each of the CovB tables is selected and output. The following statements display the ODS OUTPUT data set and create Output 20.6.3:

proc print;
   id _run_;
   by _run_;
run;

Output 20.6.3: Results of the ODS OUTPUT Statement When the PERSIST Option Is Specified

US Population Study
Concatenating Two Tables into One Data Set

_Run_ Model Dependent Variable Intercept Year YearSq
1 MODEL1 Population Intercept 20393.138485 -10.83821461 .
MODEL1 Population Year -10.83821461 0.0057650078 .

_Run_ Model Dependent Variable Intercept Year YearSq
2 MODEL1.1 Population Intercept 711450.62602 -757.2493826 0.2013282694
MODEL1.1 Population Year -757.2493826 0.8061328943 -0.000214361
MODEL1.1 Population YearSq 0.2013282694 -0.000214361 5.7010894E-8



Even though the two CovB tables do not have the same rows or columns, ODS automatically combines the two tables into one data set.

ODS Statement Placement with Interactive Procedures

Where you place a statement in an interactive procedure is critical. The following examples demonstrate the results of various placements of statements:

  • If you submit the following steps to a new SAS session, to an existing SAS session after a QUIT statement, or to an existing SAS session after a noninteractive procedure has completed, the ODS OUTPUT statement creates a SAS data set that contains the PROC GLM parameter estimates:

    ods output parameterestimates=pm;
    proc glm data=sashelp.class;
       class sex;
       model weight = sex | height / solution;
    run;
    
  • If you submit the following steps, no ODS OUTPUT SAS data set is created:

    proc reg data=sashelp.class;
       model weight = height;
    run;
    
    ods output parameterestimates=pm;
    proc glm data=sashelp.class;
       class sex;
       model weight = sex | height / solution;
    run;
    

    The preceding steps work as follows:

    • The first three statements (PROC REG, MODEL, and RUN) perform a simple regression analysis and display the parameter estimates table. This completes one RUN group.

    • PROC REG is still active when it encounters the ODS OUTPUT statement. But the first RUN group has completed, so the first parameter estimates table is no longer available for ODS to output.

    • PROC REG terminates because of the PROC GLM statement.

    • The ODS OUTPUT statement has not created an output data set when PROC REG terminates because no model was fit after the first RUN group.

    • SAS prints warning messages because the ODS OUTPUT statement could not output a parameter estimates table.

    • The ODS OUTPUT statement corresponds to the PROC REG step because PROC REG is still active when the statement is encountered. If PROC REG had ended first, then the ODS OUTPUT statement would apply to the following PROC GLM step.

  • The ODS OUTPUT statement in the following example outputs the PROC GLM parameter estimates because the QUIT statement ends the PROC REG step:

    proc reg data=sashelp.class;
       model weight = height;
    run; quit;
    
    ods output parameterestimates=pm;
    proc glm data=sashelp.class;
       class sex;
       model weight = sex | height / solution;
    run;
    
  • The ODS OUTPUT statement in the following example outputs the PROC GLM parameter estimates because the ODS OUTPUT statement appears within the PROC GLM step:

    proc reg data=sashelp.class;
       model weight = height;
    run;
    
    proc glm data=sashelp.class;
       ods output parameterestimates=pm;
       class sex;
       model weight = sex | height / solution;
    run;
    

Explicitly Ending an Interactive Procedure

You can end interactive procedures such as PROC GLM and PROC REG by submitting a RUN statement and then a QUIT statement:

proc reg data=sashelp.class;
   model weight = height;
run; quit;

Alternatively, you can end PROC GLM and PROC REG by submitting only a QUIT statement:

proc reg data=sashelp.class;
   model weight = height;
quit;

Some interactive procedures behave differently from PROC GLM and PROC REG. The GPLOT procedure does not produce results when you submit a QUIT statement but no RUN statement. You should end the IML procedure by submitting only a QUIT statement, because a RUN statement in PROC IML runs a module.