Example 20.6 RUN-Group Processing

Some SAS procedures, such as PROC REG and PROC GLM, permit you to submit statements, followed by a RUN statement, followed by more statements and more RUN statements. Each group of statements, followed by a RUN statement, is called a RUN group. These procedures can produce several blocks of output for each of several RUN groups. The procedure stays active until a QUIT statement, a DATA statement, another PROC statement, or the end of the SAS session is encountered. However, ODS settings are cleared by default at RUN-group boundaries. In the following analysis, 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= option in the ODS OUTPUT statement is required to make this happen. The PERSIST= option maintains ODS settings across RUN statements for procedures that support RUN-group processing.

Consider the following population growth trends. The population of the United States from 1790 to 1970 is fit to linear and quadratic functions of time. The quadratic term, YearSq, is created in the DATA step; this is necessary since polynomial effects such as Year*Year cannot be specified in the MODEL statement in PROC REG. The data are as follows:

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 statements, PROC REG is used, and the ODS OUTPUT statement with the PERSIST= option creates a data set with 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 the COVB matrix is requested. The RUN statement executes PROC REG and the model is fit, producing a covariance matrix of the estimates with two rows and two columns. The results are displayed in Output 20.6.1 and Output 20.6.2.

Output 20.6.1 Regression Results for the Model Population
US Population Study
Concatenating Two Tables into One Data Set

The REG Procedure
Model: MODEL1
Dependent Variable: Population

Number of Observations Read 19
Number of Observations Used 19

Analysis of Variance
Source DF Sum of
Squares
Mean
Square
F Value Pr > F
Model 1 66336 66336 201.87 <.0001
Error 17 5586.29253 328.60544    
Corrected Total 18 71923      

Root MSE 18.12748 R-Square 0.9223
Dependent Mean 69.76747 Adj R-Sq 0.9178
Coeff Var 25.98271    

Parameter Estimates
Variable DF Parameter
Estimate
Standard
Error
t Value Pr > |t|
Intercept 1 -1958.36630 142.80455 -13.71 <.0001
Year 1 1.07879 0.07593 14.21 <.0001

Output 20.6.2 CovB Matrix for the Model Population
Covariance of Estimates
Variable Intercept Year
Intercept 20393.138485 -10.83821461
Year -10.83821461 0.0057650078

In the next step, the YearSq variable is added to the model and the model is fit again, producing a covariance matrix of the estimates with three rows and three columns:

add YearSq;
print;
run; quit;

The new COVB matrix is displayed in Output 20.6.3.

Output 20.6.3 CovB Matrix for the Model Population
US Population Study
Concatenating Two Tables into One Data Set

The REG Procedure
Model: MODEL1.1
Dependent Variable: Population

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

The PERSIST=RUN option maintains the ODS selection list across RUN statements for procedures that support RUN-group processing. If the PERSIST=RUN option is omitted, the selection list is cleared when the RUN statement is encountered and only the first COVB matrix is selected. 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 matrices is selected and output. The following statements display the ODS OUTPUT SAS data set and create Output 20.6.4:

proc print;
run;

Output 20.6.4 Results of the ODS OUTPUT Statement: Specifying the PERSIST Option
US Population Study
Concatenating Two Tables into One Data Set

Obs _Run_ Model Dependent Variable Intercept Year YearSq
1 1 MODEL1 Population Intercept 20393.138485 -10.83821461 .
2 1 MODEL1 Population Year -10.83821461 0.0057650078 .
3 2 MODEL1.1 Population Intercept 711450.62602 -757.2493826 0.2013282694
4 2 MODEL1.1 Population Year -757.2493826 0.8061328943 -0.000214361
5 2 MODEL1.1 Population YearSq 0.2013282694 -0.000214361 5.7010894E-8

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