OPTBINNING Procedure

Getting Started: OPTBINNING Procedure

Note: Input data must be in a CAS table that is accessible in your CAS session. You must refer to this table by using a two-level name. The first level must be a CAS engine libref, and the second level must be the table name. For more information, see the sections Using CAS Sessions and CAS Engine Librefs and Loading a SAS Data Set onto a CAS Server in Chapter 2, Shared Concepts.

This example shows how to use the OPTBINNING procedure to fit a credit scoring model. In this example, the input data set datain contains information about fine bins. The parameter data set parms contains the constraints.

The following data set, datain, includes the bin number, number of bad observations, number of good observations, weight of evidence (WOE), variable name, lower bound, upper bound, and WOE trend:

data datain;
   input bin varB  varG  WOE  display_var $8.
         low  high   woeTrend ;
datalines;
1 106 32 -1.197703191 AGE      18 21 -0.920258863
2 54 24 -0.810930216 AGE       21 22 -0.739566193
3 94 28 -1.211090272 AGE       22 23 -0.679335303
4 93 46 -0.703958097 AGE       23 24 -0.619104414
5 170 103 -0.501069449 AGE     24 25.5 -0.558873524
1 3 7 0.8472978604 CASH        0 500 -0.175718155
2 89 72 -0.211970251 CASH     500 600 -0.129804828
3 88 54 -0.488352768 CASH     600 700 -0.120622163
4 82 70 -0.158224005 CASH     700 800 -0.111439498
5 78 82 0.0500104206 CASH     800 900 -0.102256832
6 81 67 -0.189756535 CASH     900 1000 -0.093074167
7 104 99 -0.049271049 CASH     1000 1100 -0.083891502
8 62 51 -0.195308752 CASH     1100 1200 -0.074708837
9 60 77 0.2494608596 CASH     1200 1300 -0.065526171
1 241 466 0.6593887006 INCOME   0 1000 0.2774569026
2 39 24 -0.485507816 INCOME   1000 1500 0.1286536432
3 156 95 -0.495979116 INCOME   1500 1700 0.0542520135
4 122 55 -0.79668786 INCOME   1700 1900 0.0244913616
5 54 41 -0.27541198 INCOME   1900 2000 -0.00526929
6 99 60 -0.500775288 INCOME   2000 2100 -0.020149616
7 47 28 -0.517943092 INCOME   2100 2200 -0.035029942
8 98 54 -0.595983432 INCOME   2200 2300 -0.049910268
9 131 102 -0.25022451 INCOME   2300 2500 -0.064790594
10 142 129 -0.096014653 INCOME   2500 2700 -0.094551246
11 109 107 -0.018519048 INCOME   2700 3000 -0.124311898
12 119 162 0.3084728421 INCOME   3000 3400 -0.168952876
13 46 74 0.4754236967 INCOME   3400 4000 -0.228474179
;

In the following parameter data set, parms, each row contains the constraints for each characteristic variable. The columns contain different constraints for each variable. If an upper bound value for a constraint is 0, the constraint is treated as not bounded above.

data parms;
   input display_var $8. MinBinDiff  MinBinWidth
         MaxBinWidth woeTrend  minBinG
         minBinB minBinTol maxBinTol  minNumBin
         maxNumBin;
datalines;
AGE     0.01 0 0 1 1 1 150 23250 2 5
CASH    0.01 0 0 1 1 1 150 23250 2 5
INCOME  0.01 0 0 1 1 1 150 23250 2 5
;

You can load datain and parms into your CAS session by naming your CAS engine libref in the first statement of the following DATA steps:

data mylib.datain;
   set datain;
run;

data mylib.parms;
   set parms;
run;

This statement assumes that your CAS engine libref is named mylib, but you can substitute any appropriately defined CAS engine libref.

The following statements run PROC OPTBINNING and output the model table output and solver status table status to the mylib CAS engine libref:

proc optbinning
   data=mylib.datain
   param=mylib.parms
   output=mylib.outdata
   status=mylib.status
   adjustfactor=0.2;
run;

The following statements display the mylib.output and mylib.status tables shown in Figure 1 and Figure 2:

proc print data=mylib.outdata; run;
proc print data=mylib.status; run;

Figure 1: Output

ObsDISPLAY_VARLOWHIGHWOE
1AGE1823.0-0.30951
2AGE2325.50.22880
3CASH0800.0-0.14409
4CASH8001100.00.05232
5CASH11001300.00.15905
6INCOME01000.00.66367
7INCOME10004000.0-0.21735


In Figure 1, the observations are grouped by variable names. Within each group, each observation shows the lower bound, upper bound, and WOE of a coarse bin.

Figure 2: Status

ObsDISPLAY_VARSTATUS
1AGEOPTIMAL
2CASHOPTIMAL
3INCOMEOPTIMAL


In Figure 2, each observation shows the solution status of a characteristic variable. When all the constraints on a variable are satisfied, the status is OPTIMAL. If any constraint is violated, the status is INFEASIBLE.

Last updated: July 11, 2024