The script begins by creating an internal dataset named 'Insure' from raw data ('datalines'). This dataset contains the number of claims (n), the cost of claims (c), car type (Car), and age (Age). A variable 'ln' is also calculated as the natural logarithm of 'n', used as an offset in the model. Next, a Poisson regression is fitted using PROC GENMOD, modeling 'c' based on 'Car' and 'Age', with 'ln' as the offset and a Poisson distribution. Intermediate ODS results are traced. A second PROC GENMOD execution, with ODS disabled, exports observation statistics (ObStats) to a new dataset 'myObStats', renaming the prediction variable. This dataset is then sorted by the predicted value (descending) and finally printed using PROC PRINT, with a descriptive title.
Data Analysis
Type : CREATION_INTERNE
The 'Insure' dataset is created directly within the script using a DATA STEP instruction and data provided via 'datalines'. No external data or SASHELP datasets are used as a primary source.
1 Code Block
DATA STEP Data
Explanation : This code block creates the 'Insure' dataset. It reads the variables 'n' (number of observations), 'c' (cost), 'Car' (car category), and 'Age' (age category). The 'ln' variable is calculated as the natural logarithm of 'n', which will be used as an offset in the Poisson regression model.
Copied!
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
;
1
DATA Insure;
2
INPUT n c Car $ Age;
3
ln = log(n);
4
DATALINES;
5
50042 Small 1
6
120037 Medium 1
7
1001 Large 1
8
400101 Small 2
9
50073 Medium 2
10
30014 Large 2
11
;
2 Code Block
PROC GENMOD
Explanation : This block executes the GENMOD procedure to fit a Poisson regression model. 'Car' and 'Age' are declared as classification variables. The model specifies 'c' as the dependent variable, 'Car' and 'Age' as predictors, a Poisson distribution (dist=poisson), a logarithmic link function (link=log), and 'ln' as the offset (offset=ln). The 'obstats' option requests observation-level statistics. 'ODS TRACE ON' is used to display the names of the output objects created by the procedure.
Copied!
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;
1
ods trace on;
2
3
PROC GENMODDATA=insure;
4
class car age;
5
model c = car age / dist=poisson link=log offset=ln obstats;
6
RUN;
7
8
ods trace off;
3 Code Block
PROC GENMOD Data
Explanation : Here, PROC GENMOD is executed again, but with 'ODS SELECT NONE' to suppress all standard ODS output. The 'ODS OUTPUT ObStats=myObStats(...)' statement specifically captures the 'ObStats' output object (observation statistics) into a new SAS dataset called 'myObStats'. Only the variables 'car', 'age', and 'pred' (renamed to 'PredictedValue') are kept in this new dataset.
Copied!
ods select none;
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;
1
ods select none;
2
PROC GENMODDATA=insure;
3
class car age;
4
model c = car age / dist=poisson link=log offset=ln obstats;
5
ods OUTPUT ObStats=myObStats(keep=car age pred
6
rename=(pred=PredictedValue));
7
RUN;
4 Code Block
PROC SORT
Explanation : This block uses PROC SORT to sort the 'myObStats' dataset. The sorting is performed by the 'PredictedValue' variable in descending order ('descending').
Copied!
proc sort data=myObStats;
by descending PredictedValue;
run;
1
2
PROC SORT
3
DATA=myObStats;
4
BY descending PredictedValue;
5
RUN;
6
5 Code Block
PROC PRINT
Explanation : This block concludes the analysis by displaying the content of the sorted 'myObStats' dataset using PROC PRINT. 'ODS SELECT ALL' reactivates all ODS output. The 'noobs' option suppresses the observation number column. A subtitle ('title2') is added to describe the content of the printed table.
Copied!
ods select all;
proc print data=myObStats noobs;
title2 'Values of Car, Age, and the Predicted Values';
run;
1
ods select all;
2
PROC PRINTDATA=myObStats noobs;
3
title2 'Values of Car, Age, and the Predicted Values';
4
RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : S A S S A M P L E L I B R A R Y
NAME: ODSEX4
TITLE: Documentation Example 4 for ODS
PRODUCT: STAT
SYSTEM: ALL
KEYS: ODS
PROCS: GENMOD
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.