Published on :
Statistical CREATION_INTERNE

Insurance Claims

This code is also available in: Deutsch Español Français
Awaiting validation
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!
1DATA Insure;
2 INPUT n c Car $ Age;
3 ln = log(n);
4 DATALINES;
5 500 42 Small 1
61200 37 Medium 1
7 100 1 Large 1
8 400 101 Small 2
9 500 73 Medium 2
10 300 14 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!
1ods trace on;
2 
3PROC GENMOD DATA=insure;
4 class car age;
5 model c = car age / dist=poisson link=log offset=ln obstats;
6RUN;
7 
8ods 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!
1ods select none;
2PROC GENMOD DATA=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));
7RUN;
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!
1 
2PROC SORT
3DATA=myObStats;
4BY descending PredictedValue;
5RUN;
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!
1ods select all;
2PROC PRINT DATA=myObStats noobs;
3 title2 'Values of Car, Age, and the Predicted Values';
4RUN;
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