%MM_Severity_Create_Scorecode Autocall Macro

Creates DATA step statements to compute the predicted values of a model that you create using the SEVERITY procedure.

Syntax

Arguments

ParamEst=severity-parmeter-estimate-dataset

specifies the name of the parameter estimations output data. This data set is created when you specify the OUTEST= option in the PROC SEVERITY statement.

ModelInfo=model-info-data-set

specifies the name of the model information output data set. This data set is created when you specify the OUTMODELINGINFO= option in the PROC SEVERITY statement.

FileRef=output-fileref

specifies the fileref that defines the location of the macro output files.

Default The SAS log

PredPrefix=dependent-variable-prefix

specifies a prefix for the predicted dependent variable. The variable is named in the PROC SEVERITY LOSS= statement. When is prefix is applied to the dependent variable, this new name becomes the prediction variable.

Default P_

Details

To create score code for a model that you create with PROC SEVERITY, include the following SAS code:
  1. Use a LIBNAME statement to identify the location of the output that you create using PROC SEVERITY.
  2. Build your model using PROC SEVERITY. Specify the OUTEST= option to create the ParameterEstimates data. Specify OUTMODELINFO= option to create the ModelInformation data set. Close the ODS OUTPUT destination.
  3. Use the FILENAME statement to define a fileref for the macro output location.
  4. Invoke the %MM_Severity_Create_Scorecode Macro.

Example: Generate the PROC SEVERITY Score Code for Insurance Risk

Create the Sample Insurance Data

%let MyProj = C:\Users\sasdemo;
libname Severity "&MyProj.\Severity\Test";
   
data Severity.phf;
   
   /* Regression Coefficient for the Intercept Term */
   retain fIntercept 6.8024;
   
   /* Regression Coefficient for continuous AgeDriver */
   retain fAgeDriver 0.01234;
   
   /* Regression Coefficient for the three dummy indicators for nominal CarType */
   retain fCarType_SEDAN 0;
   retain fCarType_SPORT 1.0;
   retain fCarType_TRUCK 0.5;
   
   /* Regression Coefficient for the two dummy indicators for nominal Gender */
   retain fGender_Female -1.5;
   retain fGender_Male 0;
   
   /* Regression Coefficient for the two dummy indicators for nominal HomeOwner */
   retain fHomeOwner_NO 0;
   retain fHomeOwner_YES 0.7;
   
   /* Regression Coefficient for continuous IS */
   retain fIS -0.00456;
   
   /* Regression Coefficient for continuous MileageDriven */
   retain fMileageDriven 0.013579;
   
   /* Variable Labels */
   label AgeDriver = 'Age of Driver';
   
   label AmountLoss = 'Amount of Loss in Dollars';
   format AmountLoss dollar.;
   
   label CarType_SEDAN = 'Indicator of Car Type is Sedan';
   label CarType_SPORT = 'Indicator of Car Type is Sport';
   label CarType_TRUCK = 'Indicator of Car Type is Truck';
   
   label EExp = 'Earned Exposure in Units of One Year';
   
   label ExpYr = 'Exposure Year';
   
   label Gender_Female = 'Indicator of Gender is Female';
   label Gender_Male = 'Indicator of Gender is Male';
   
   label HomeOwner_NO = 'Indicator of Home Ownership is No';
   label HomeOwner_YES = 'Indicator of Home Ownership is Yes';
   
   label IS = 'Insurance Score of Driver';
   
   label MileageDriven = 'Mileage Driven in Units of 1,000 Miles';
   
   label PolicyId = 'Policy Identifier';
   
   call streaminit(27513);
     do PolicyId = 00001 to 00099;
       StartYr = 2000 + 
                 rand('table', 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1);
         do ExpYr = StartYr to 2011;
            EExp = rand('uniform');
   
            AgeDriver = 18 + rand('binomial',0.375, 72);
   
            CarType_SEDAN = 0;
            CarType_SPORT = 0;
            CarType_TRUCK = 0;
            select (rand('table', 0.4999, 0.2999, 0.1999, 0.0003));
               when (1) CarType_SEDAN = 1;
               when (2) CarType_SPORT = 1;
               when (3) CarType_TRUCK = 1;
               otherwise
               do;
                  CarType_SEDAN = .;
                  CarType_SPORT = .;
                  CarType_TRUCK = .;
               end;
         end;
   
         Gender_Female = 0;
         Gender_Male = 0;
         if (EExp lt 0.4999) then Gender_Female = 1;
           else if (EExp lt 0.9999) then Gender_Male = 1;
            else
            do;
               Gender_Female = .;
               Gender_Male = .;
            end;
   
            HomeOwner_NO = 0;
            HomeOwner_YES = 0;
            if (rand('bernoulli', 0.25) eq 1) then HomeOwner_YES = 1;
            else HomeOwner_NO = 1;
   
            IS = round(rand('gamma', 600));
            if (IS gt 800) then IS = 800;
            else if (IS lt 1) then IS = 1;
   
            MileageDriven = rand('gamma', 12);      
            /* Annual Mileage Driven in unit of 1000 miles */
   
            if (nmiss(MileageDriven,AgeDriver,CarType_SEDAN,CarType_TRUCK, 
                CarType_SPORT,
                Gender_Male,Gender_Female,
                HomeOwner_YES,HomeOwner_NO,IS) eq 0) 
              then
            do;
               mu = fIntercept
                    + fAgeDriver * (28 - AgeDriver)
                    + fCarType_SEDAN * CarType_SEDAN + fCarType_SPORT 
                    * CarType_SPORT 
                    + fCarType_TRUCK * CarType_TRUCK 
                    + fGender_Female * Gender_Female + fGender_Male 
                    * Gender_Male
                    + fHomeOwner_NO * HomeOwner_NO + fHomeOwner_YES 
                    * HomeOwner_YES
                    + fIS * IS
                    + fMileageDriven * (MileageDriven - 12);
               AmountLoss = exp(mu) * rand('gamma', 25);
            end;
            else AmountLoss = .;
            output;
     end;
    end;
   drop fAgeDriver fCarType_SEDAN fCarType_TRUCK fCarType_SPORT fGender_Male 
        fGender_Female fHomeOwner_YES fHomeOwner_NO fIntercept fIS fMileageDriven;
      drop mu StartYr;
run;

Run the Sample Program

%let MyProj = C:\Users\sasdemo;
libname Severity "&MyProj.\Severity\Test";
  
title "SCALEMODEL and all applicable distributions";
  
%let model = 1;
%let predlist = AgeDriver CarType_SEDAN CarType_TRUCK CarType_SPORT 
     Gender_Male Gender_Female HomeOwner_YES HomeOwner_NO IS MileageDriven;

/* Build the model and obtain the required datasets */
proc severity data = Severity.phf
              outest = Severity.ParamEst_&Model.
              outmodelinfo = Severity.ModelInfo_&model.;
   loss AmountLoss;
   dist _predefined_ stweedie;
   scalemodel &predlist.;
   nloptions maxiter = 1000;
run;
  
/* Define the fileref for the output syntax */
filename ThisFile "&MyProj.\Severity\Test\ScoreCode_&Model..sas";
  
/* Invoke the macro */
%mm_severity_create_scorecode
   (
     ParamEst = Severity.ParamEst_&Model.,
     ModelInfo = Severity.ModelInfo_&model.,
     FileRef = ThisFile,
     PredPrefix = MyPred_
  );
  
/* Execute the score codes within a DATA STEP */
data Severity.phf_wPrediction;
   set Severity.phf;
   %include ThisFile;
run;
  
proc contents data = Severity.phf_wPrediction;
run;

The Generated Score Code and Output Tables

Generated Score Code
/**********************************************************************/
/* Begin scoring code for SEVERITY                                    */
/* Created By: sasdemo                                                */
/* Date: June 30, 2015                                                */
/* Time: 12:06:28                                                     */
/**********************************************************************/

LENGTH _WARN_ $ 4;
_WARN_ = '    ';
LABEL _WARN_ = "Warnings" ;

_nInputMiss = 0;

/**********************************************************************/
/* Check the SCALEMODEL regression variables                          */
/**********************************************************************/

IF ( MISSING( MileageDriven ) EQ 1 ) THEN _nInputMiss = _nInputMiss + 1;

IF ( MISSING( IS ) EQ 1 ) THEN _nInputMiss = _nInputMiss + 1;

/* NOTE: HomeOwner_NO is not checked for missing values because it is a redundant regressor. */

IF ( MISSING( HomeOwner_YES ) EQ 1 ) THEN _nInputMiss = _nInputMiss + 1;

/* NOTE: Gender_Female is not checked for missing values because it is a redundant regressor. */

IF ( MISSING( Gender_Male ) EQ 1 ) THEN _nInputMiss = _nInputMiss + 1;

IF ( MISSING( CarType_SPORT ) EQ 1 ) THEN _nInputMiss = _nInputMiss + 1;

IF ( MISSING( CarType_TRUCK ) EQ 1 ) THEN _nInputMiss = _nInputMiss + 1;

/* NOTE: CarType_SEDAN is not checked for missing values because it is a redundant regressor. */

IF ( MISSING( AgeDriver ) EQ 1 ) THEN _nInputMiss = _nInputMiss + 1;
/**********************************************************************/
/* Calculate scores only if current record contains valid values      */
/**********************************************************************/

IF ( _nInputMiss EQ 0 ) THEN DO;

   /**********************************************************************/
   /* Distribution: BURR                                                 */
   /**********************************************************************/

   _XBETA_ = 0;
   _XBETA_ = _XBETA_ + 1.401229993940100E-02 * MileageDriven ;
   _XBETA_ = _XBETA_ - 4.744055757460300E-03 * IS ;
   /* NOTE: HomeOwner_NO is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ + 7.381815343018200E-01 * HomeOwner_YES ;
   /* NOTE: Gender_Female is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ + 1.495958484730900E+00 * Gender_Male ;
   _XBETA_ = _XBETA_ + 9.886615491163800E-01 * CarType_SPORT ;
   _XBETA_ = _XBETA_ + 4.731784863675400E-01 * CarType_TRUCK ;
   /* NOTE: CarType_SEDAN is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ - 1.066440552950800E-02 * AgeDriver ;

   MyPred_AmountLoss_BURR = 6.236121394142300E+03 * EXP(_XBETA_);

   /**********************************************************************/
   /* Distribution: EXP                                                  */
   /**********************************************************************/

   _XBETA_ = 0;
   _XBETA_ = _XBETA_ + 1.364239152005100E-02 * MileageDriven ;
   _XBETA_ = _XBETA_ - 4.739639251429400E-03 * IS ;
   /* NOTE: HomeOwner_NO is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ + 7.307690977221500E-01 * HomeOwner_YES ;
   /* NOTE: Gender_Female is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ + 1.496025385765200E+00 * Gender_Male ;
   _XBETA_ = _XBETA_ + 9.916620991492000E-01 * CarType_SPORT ;
   _XBETA_ = _XBETA_ + 4.644249484904200E-01 * CarType_TRUCK ;
   /* NOTE: CarType_SEDAN is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ - 1.151946645256000E-02 * AgeDriver ;

   MyPred_AmountLoss_EXP = 6.506747031895200E+03 * EXP(_XBETA_);

   /**********************************************************************/
   /* Distribution: GAMMA                                                */
   /**********************************************************************/

   _XBETA_ = 0;
   _XBETA_ = _XBETA_ + 1.364239160569600E-02 * MileageDriven ;
   _XBETA_ = _XBETA_ - 4.739639073904200E-03 * IS ;
   /* NOTE: HomeOwner_NO is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ + 7.307690978471100E-01 * HomeOwner_YES ;
   /* NOTE: Gender_Female is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ + 1.496025385874300E+00 * Gender_Male ;
   _XBETA_ = _XBETA_ + 9.916621000665000E-01 * CarType_SPORT ;
   _XBETA_ = _XBETA_ + 4.644249491258800E-01 * CarType_TRUCK ;
   /* NOTE: CarType_SEDAN is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ - 1.151946594479500E-02 * AgeDriver ;

   MyPred_AmountLoss_GAMMA = 6.506745978302000E+03 * EXP(_XBETA_);
   /**********************************************************************/
   /* Distribution: GPD                                                  */
   /**********************************************************************/

   _XBETA_ = 0;
   _XBETA_ = _XBETA_ + 1.364260675458400E-02 * MileageDriven ;
   _XBETA_ = _XBETA_ - 4.739190610741700E-03 * IS ;
   /* NOTE: HomeOwner_NO is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ + 7.307694223592400E-01 * HomeOwner_YES ;
   /* NOTE: Gender_Female is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ + 1.496025653107000E+00 * Gender_Male ;
   _XBETA_ = _XBETA_ + 9.916644144925200E-01 * CarType_SPORT ;
   _XBETA_ = _XBETA_ + 4.644265557308700E-01 * CarType_TRUCK ;
   /* NOTE: CarType_SEDAN is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ - 1.151818427565500E-02 * AgeDriver ;

   MyPred_AmountLoss_GPD = 6.504569551883800E+03 * EXP(_XBETA_);

   /**********************************************************************/
   /* Distribution: IGAUSS                                               */
   /**********************************************************************/

   _XBETA_ = 0;
   _XBETA_ = _XBETA_ + 1.375427253970500E-02 * MileageDriven ;
   _XBETA_ = _XBETA_ - 4.808982977719000E-03 * IS ;
   /* NOTE: HomeOwner_NO is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ + 7.279886646359200E-01 * HomeOwner_YES ;
   /* NOTE: Gender_Female is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ + 1.499838197531700E+00 * Gender_Male ;
   _XBETA_ = _XBETA_ + 9.940256355577800E-01 * CarType_SPORT ;
   _XBETA_ = _XBETA_ + 4.644584176107000E-01 * CarType_TRUCK ;
   /* NOTE: CarType_SEDAN is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ - 1.161363856490700E-02 * AgeDriver ;

   MyPred_AmountLoss_IGAUSS = 6.790140708730100E+03 * EXP(_XBETA_);

   /**********************************************************************/
   /* Distribution: LOGN                                                 */
   /**********************************************************************/

   _XBETA_ = 0;
   _XBETA_ = _XBETA_ + 1.379535910756300E-02 * MileageDriven ;
   _XBETA_ = _XBETA_ - 4.808040604328300E-03 * IS ;
   /* NOTE: HomeOwner_NO is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ + 7.286190149538200E-01 * HomeOwner_YES ;
   /* NOTE: Gender_Female is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ + 1.499292691976100E+00 * Gender_Male ;
   _XBETA_ = _XBETA_ + 9.935622786295200E-01 * CarType_SPORT ;
   _XBETA_ = _XBETA_ + 4.647870916071300E-01 * CarType_TRUCK ;
   /* NOTE: CarType_SEDAN is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ - 1.152580789026700E-02 * AgeDriver ;

   MyPred_AmountLoss_LOGN = 6.759869565247100E+03 * EXP(_XBETA_);

   /**********************************************************************/
   /* Distribution: PARETO                                               */
   /**********************************************************************/

   _XBETA_ = 0;
   _XBETA_ = _XBETA_ + 1.365643731959700E-02 * MileageDriven ;
   _XBETA_ = _XBETA_ - 4.710463064928600E-03 * IS ;
   /* NOTE: HomeOwner_NO is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ + 7.307900535342100E-01 * HomeOwner_YES ;
   /* NOTE: Gender_Female is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ + 1.496043364894300E+00 * Gender_Male ;
   _XBETA_ = _XBETA_ + 9.918130012553400E-01 * CarType_SPORT ;
   _XBETA_ = _XBETA_ + 4.645298660617500E-01 * CarType_TRUCK ;
   /* NOTE: CarType_SEDAN is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ - 1.143601522019100E-02 * AgeDriver ;

   MyPred_AmountLoss_PARETO = 6.367949946138600E+03 * EXP(_XBETA_);

   /**********************************************************************/
   /* Distribution: STWEEDIE                                             */
   /**********************************************************************/

   _XBETA_ = 0;
   _XBETA_ = _XBETA_ + 1.346890420267100E-02 * MileageDriven ;
   _XBETA_ = _XBETA_ - 4.675720482528600E-03 * IS ;
   /* NOTE: HomeOwner_NO is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ + 7.318380293889600E-01 * HomeOwner_YES ;
   /* NOTE: Gender_Female is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ + 1.493775242549600E+00 * Gender_Male ;
   _XBETA_ = _XBETA_ + 9.908288084345400E-01 * CarType_SPORT ;
   _XBETA_ = _XBETA_ + 4.641286573822800E-01 * CarType_TRUCK ;
   /* NOTE: CarType_SEDAN is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ - 1.156384352057300E-02 * AgeDriver ;

   MyPred_AmountLoss_STWEEDIE = 6.293220261934300E+03 * EXP(_XBETA_);

   /**********************************************************************/
   /* Distribution: WEIBULL                                              */
   /**********************************************************************/

 _XBETA_ = 0;
   _XBETA_ = _XBETA_ + 1.282907588332400E-02 * MileageDriven ;
   _XBETA_ = _XBETA_ - 4.480114005729500E-03 * IS ;
   /* NOTE: HomeOwner_NO is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ + 7.297672767727700E-01 * HomeOwner_YES ;
   /* NOTE: Gender_Female is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ + 1.488831397013200E+00 * Gender_Male ;
   _XBETA_ = _XBETA_ + 9.931730126153400E-01 * CarType_SPORT ;
   _XBETA_ = _XBETA_ + 4.546576968650700E-01 * CarType_TRUCK ;
   /* NOTE: CarType_SEDAN is skipped because it is a redundant regressor. */
   _XBETA_ = _XBETA_ - 1.211172101144000E-02 * AgeDriver ;

   MyPred_AmountLoss_WEIBULL = 5.778646806752700E+03 * EXP(_XBETA_);

END;

ELSE DO;

   /**********************************************************************/
   /* Set _WARN_ value                                                   */
   /**********************************************************************/

   SUBSTR(_WARN_,1,1) = 'M';
END;

LABEL MyPred_AmountLoss_BURR = "Predicted mean for the Burr Distribution" ;

LABEL MyPred_AmountLoss_EXP = "Predicted mean for the Exponential Distribution" ;

LABEL MyPred_AmountLoss_GAMMA = "Predicted mean for the Gamma Distribution" ;

LABEL MyPred_AmountLoss_GPD = "Predicted mean for the Generalized Pareto Distribution" ;

LABEL MyPred_AmountLoss_IGAUSS = "Predicted mean for the Inverse Gaussian Distribution" ;

LABEL MyPred_AmountLoss_LOGN = "Predicted mean for the Lognormal Distribution" ;

LABEL MyPred_AmountLoss_PARETO = "Predicted mean for the Pareto Distribution" ;

LABEL MyPred_AmountLoss_STWEEDIE = "Predicted mean for the Tweedie Distribution with Scale Parameter" ;

LABEL MyPred_AmountLoss_WEIBULL = "Predicted mean for the Weibull Distribution" ;

DROP _nInputMiss _XBETA_;

/**********************************************************************/
/* End scoring code for SEVERITY                                      */
/**********************************************************************/
The following tables are a sampling of the output tables that are created by the example. For each distribution type, PROC SEVERITY creates these tables: Distribution Information, Convergence Status, Optimization Summary, Fit Statistics, and Parameterization Estimation. The output displays the tables for the stweedie distribution.
The SEVERITY Procedure Input Data Set and Model Selection Table
The SEVERITY Procedure Distribution, Convergence, and Optimization Tables
The SEVERITY Procedure Fit Statistics Table
The SEVERITY Procedure Parameter Estimates Table
The CONTENTS Procedure Output
The CONTENTS Procedure Engine and Host Information
The CONTENTS Procedure Variable Listing
Last updated: February 22, 2017