Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Using the Output Delivery System

Example 15.9: Concatenating Output Data Sets: RUN Group Processing

This example demonstrates how you can write multiple tables to a single data set using the MATCH_ALL= and PERSIST= options in the ODS OUTPUT statement. The PERSIST= option maintains ODS settings across RUN statements for procedures that support run-group processing. In the following analysis, the REG procedure is invoked and the covariance matrix of the estimates is output for two different models. The flexibility of the ODS OUTPUT statement enables you to create a single data set that contains both of the resulting covariance matrices.

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. Note that the quadratic term, YearSq, is created in the DATA step; this is done since polynomial effects such as Year*Year cannot be specified in the MODEL statement in PROC REG. The data are as follows:

   title1 'Concatenating Two Tables into One Data Set';
   title2 'US Population Study';
   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, the REG procedure is invoked and the ODS statement requests that a data set be created to contain the COVB matrix (the covariance matrix of the estimates).

The ODS statement uses the MATCH_ALL= and PERSIST= options. The effect of these options is to create a separate data set for each COVB matrix encountered in the entire procedure step.

   proc reg data=USPopulation;
      ods output covb(match_all=Bname         /* correct */
                      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 the REG procedure and the model is fit, producing a covariance matrix of the estimates with 2 rows and 2 columns.

Output 15.9.1: Regression Results for the Model Population=Year

                                   Concatenating Two Output Tables into One Data Set
                                                  US Population Study

                                                   The REG Procedure
                                                     Model: MODEL1
                                            Dependent Variable: Population 

                                                  Analysis of Variance
 
                                                         Sum of           Mean
                     Source                   DF        Squares         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
 
                                               Parameter       Standard
                         Variable      DF       Estimate          Error    t Value    Pr > |t|

                         Intercept      1    -1958.36630      142.80455     -13.71      <.0001
                         Year           1        1.07879        0.07593      14.21      <.0001

Output 15.9.2: CovB Matrix for the Model Population=Year

               Concatenating Two Output Tables into One Data Set
                              US Population Study

                               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 step, the YearSq variable is added to the model and the model is again fit, producing a covariance matrix of the estimates with three rows and three columns.

   add YearSq;
   print;
   run;

The results of the regression are displayed in Output 15.9.3.

Output 15.9.3: Regression Results for the Model Population=Year YearSq
               Concatenating Two Output Tables into One Data Set
                              US Population Study

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

                              Analysis of Variance
 
                                     Sum of           Mean
 Source                   DF        Squares         Square    F Value    Pr > F

 Model                     2          71799          35900    4641.72    <.0001
 Error                    16      123.74557        7.73410                     
 Corrected Total          18          71923                                    


              Root MSE              2.78102    R-Square     0.9983
              Dependent Mean       69.76747    Adj R-Sq     0.9981
              Coeff Var             3.98613                       


                              Parameter Estimates
 
                           Parameter       Standard
     Variable      DF       Estimate          Error    t Value    Pr > |t|

     Intercept      1          20450      843.47533      24.25      <.0001
     Year           1      -22.78061        0.89785     -25.37      <.0001
     YearSq         1        0.00635     0.00023877      26.58      <.0001

Output 15.9.4: CovB Matrix for the Model Population=Year YearSq
               Concatenating Two Output Tables into One Data Set
                              US Population Study

                               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


In the preceding analysis, two COVB matrices are generated, corresponding to the two fitted models. When you select two output tables that have the same name but different structures, specify the MATCH_ALL option to create a new data set for each table.

When you specify MATCH_ALL=name, a macro variable called name is created that contains the names of all the generated data sets. Thus, in this example, ODS creates two data sets (one for each model fit in the PROC REG run) and the macro variable Bname is created to contain the names of the two data sets.

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 REG procedure step. This ensures that each of the COVB matrices is selected and output.

The first output data set has the specified name BMatrix. Subsequent data set names are automatically created by appending the numerals 1, 2, 3, ... , as needed. In this case, the names of the data sets are BMatrix and BMatrix1. The names are contained in the macro variable Bname.

The result of the ODS OUTPUT statement is displayed with the following statements. The SET &BName statement reads observations from all data sets listed by the macro variable Bname. The variable Bname contains the two values (BMatrix and BMatrix1). Thus, the SET statement reads observations from these two data sets. Note that, when you refer to a macro variable, an ampersand (&) always precedes a macro variable name but is not part of the name.

   data new2;
      title 'The COVB Matrix Data Set, Using the PERSIST option';
      title2 'Concatenating Two Tables into One Data Set';
      set &Bname;
   run;
   proc print;
   run;

The data set new2 contains the two data sets created from the two COVB matrices.

Output 15.9.5: Results of the ODS OUTPUT Statement, Specifying the PERSIST Option

                                   The COVB Matrix Data Set, Using the PERSIST option
                                   Concatenating Two Output 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

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.