Using the Output Delivery System |
In this example, the GENMOD procedure is used to perform Poisson regression, and part of the resulting procedure output is written to a SAS data set with the ODS OUTPUT statement. Insurance claims data are classified by two factors: age group (with two levels) and car type (with three levels). The following statements create the data set Insure:
title 'Insurance Claims'; 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 ;
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 of a policyholder (classified into two groups).
You can use PROC GENMOD to perform a Poisson regression analysis of these data with a log link function. Assume that the number of claims variable c has a Poisson probability distribution and the log of its mean, , is related to the factors Car and Age.
The following statements obtain the names of the tables produced by this PROC GENMOD run. The ODS TRACE statement lists the trace record. If you already know the names, such as by looking them up in the procedure documentation, you do not have to run this step. The following step displays the trace information:
ods trace on; proc genmod data=insure; class car age; model c = car age / dist = poisson link = log offset = ln obstats; run; ods trace off;
The trace record from the SAS log is displayed next:
Output Added: ------------- Name: ModelInfo Label: Model Information Template: Stat.Genmod.ModelInfo Path: Genmod.ModelInfo ------------- Output Added: ------------- Name: NObs Label: Number of observations summary Template: Stat.Genmod.NObs Path: Genmod.NObs ------------- Output Added: ------------- Name: ClassLevels Label: Class Level Information Template: Stat.Genmod.Classlevels Path: Genmod.ClassLevels ------------- Output Added: ------------- Name: ParmInfo Label: Parameter Information Template: Stat.Genmod.Parminfo Path: Genmod.ParmInfo ------------- Output Added: ------------- Name: ModelFit Label: Criteria For Assessing Goodness Of Fit Template: stat.genmod.ModelFit Path: Genmod.ModelFit ------------- Output Added: ------------- Name: ConvergenceStatus Label: Convergence Status Template: Stat.Genmod.ConvergenceStatus Path: Genmod.ConvergenceStatus ------------- Output Added: ------------- Name: ParameterEstimates Label: Analysis Of Parameter Estimates Template: stat.genmod.parameterestimates Path: Genmod.ParameterEstimates ------------- Output Added: ------------- Name: ObStats Label: Observation Statistics Template: Stat.Genmod.Obstats Path: Genmod.ObStats -------------
In the following step, the ODS OUTPUT statement writes the ODS table ObStats to a SAS data set named myObStats. The LISTING destination is closed so that no output is displayed. All of the usual data set options, such as the KEEP= or RENAME= option, can be used in the ODS OUTPUT statement. Thus, to create the myObStats data set so that it contains only certain columns from the ObStats table, you can use the data set options as follows:
ods listing close; proc genmod data=insure; class car age; model c = car age / dist=poisson link=log offset=ln obstats; ods output ObStats=myObStats(keep=car age pred rename=(pred=PredictedValue)); 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 PredictedValue. The following statements sort the output data set myObStats, reopen the LISTING destination for output, and produce Output 20.4.1:
proc sort data=myObStats; by descending PredictedValue; run; ods listing; proc print data=myObStats noobs; title2 'Values of Car, Age, and the Predicted Values'; run;
When a destination is closed, it remains closed until it is explicitly reopened.
Copyright © SAS Institute, Inc. All Rights Reserved.