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

Example 15.6: Creating an Output Data Set from an ODS Table

The ODS OUTPUT statement creates SAS data sets from ODS tables. In the following example, the GENMOD procedure is invoked to perform Poisson regression and part of the resulting procedure output is written to a SAS data set.

Suppose the following insurance claims data are classified by two factors: age group (with two levels) and car type (with three levels).

   data insure;
      input n c car$ age;
      ln = log(n);
      datalines;
   500   42  small  1
   1200  37  medium 1
   100    1  large  1
   400  101  small  2
   500   73  medium 2
   300   14  large  2
   ;

In the data set insure, the variable n represents the number of insurance policyholders and the variable c represents the number of insurance claims. The variable car represents the type of car involved (classified into three groups) and the variable age is the age group of a policyholder (classified into two groups).

In the statements that follow, PROC GENMOD performs a Poisson regression analysis of these data with a log link function. Assume that the number of claims c has a Poisson probability distribution and that its mean, \mu_i, is related to the factors car and age.

Determining the Names of the ODS Tables

The purpose of the following statements is to obtain the names of the output tables produced in this PROC GENMOD run. The ODS TRACE statement lists the trace record, and the SAS listing destination is closed so that no output is displayed.

   ods trace on;
   ods listing close;

   proc genmod data=insure;
      class car age;
      model c = car age / dist   = poisson
                          link   = log
                          offset = ln
                          obstats;
   run;
   ods trace off;

Output 15.6.1: The ODS TRACE: Partial Contents of the SAS Log

           ods trace on;
           ods listing close;
       
           proc genmod data=insure;
              class car age;
              model c = car age / dist   = poisson
                                  link   = log
                                  offset = ln
                                  obstats;
           run;

Output Added:
-------------
Name:       ModelInfo
Label:      Model Information
Template:   Stat.Genmod.ModelInfo
Path:       Genmod.ModelInfo
-------------
            .
            .
            .
            .

Output Added:
-------------
Name:       ParameterEstimates
Label:      Analysis Of Parameter Estimates
Template:   stat.genmod.parameterestimates
Path:       Genmod.ParameterEstimates
-------------
NOTE: The scale parameter was held fixed.

Output Added:
-------------
Name:       ObStats
Label:      Observation Statistics
Template:   Stat.Genmod.Obstats
Path:       Genmod.ObStats
-------------

By default, the trace record is written to the SAS log, as displayed in Output 15.6.1. Note that you can alternatively specify that the information be interleaved with the procedure output in the SAS listing (see Example 15.3).

Creating the Output Data Set

In the statements that follow, the ODS OUTPUT statement writes the ODS table "ObStats" to a SAS data set called myObStats. All of the usual data set options, such as the KEEP= or RENAME= option, can be used in the ODS OUTPUT statement. Thus, to modify the ObStats data set so that it contains only certain variables, you can use the data set options as follows.
   ods output ObStats=myObStats
                 (keep=Car Age Pred
                  rename=(Pred=PredictedValue));


   proc genmod data=insure;
      class car age;
      model c = car age / dist   = poisson
                          link   = log
                          offset = ln
                          obstats;
   run;

The KEEP= option in the ODS OUTPUT statement specifies that only the variables Car, Age, and Pred are written to the data set, and the Pred variable is renamed to PredictedValue. The GENMOD procedure is again invoked. In order to limit the amount of displayed output, the SAS listing destination remains closed. When a destination is closed, it remains closed until it is explicitly reopened.

In the following statements, the output data set myObStats is sorted, and the SAS listing is reopened for output. The results are displayed in Output 15.6.2.

    proc sort data=myObStats;
       by descending PredictedValue;
    run;

    ods listing;
    proc print data=myObStats noobs;
    title 'Values of Car, Age, and the Predicted Values';
    run;

Output 15.6.2: The ObStats Table, Created as a SAS Data Set

                  Values of Car, Age, and the Predicted Values

                                            Predicted
                            car      age      Value

                           small      2      107.2011
                           medium     2     67.025444
                           medium     1     42.974556
                           small      1     35.798902
                           large      2     13.773459
                           large      1     1.2265414

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

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