BINNING Procedure
Example 5.4 Cutpoint Binning
(View the complete code for this example.)
The following DATA step generates a data table that contains 10 observations of a target variable (y), two continuous variables (x1, x2), and some other variables:
data mylib.ex4;
input cl1 $ cl2 x1 x2 y freq id;
datalines;
a 2 3 7 9 2 1
a 2 2 6 8 3 2
a 3 0 1 5 0 3
c 2 3 7 4 . 4
c 2 . 4 8 -5 5
a 3 6 7 5 3 6
b 1 4 4 8 4 7
b 2 5 6 3 3 8
b 1 6 4 8 1 9
b 2 3 2 6 3 10
;
The following statements show how you can use the BINNING procedure to perform cutpoint binning:
proc binning data=mylib.ex4 numbin=4 method=cutpts;
input x2/cutpts(2, 2.3, 4.5);
input x1/numbin=3 cutpts(3.1, 5);
run;
The DATA= option specifies the input data table. The METHOD= option requests that the cutpoint binning method be used. The first INPUT statement names one continuous variable x2 as the first input variable for binning, with four bins specified by the NUMBIN= global option. The second INPUT statement names another continuous variable x1 as the second input variable for binning with three bins. For the first input variable x2, 2, 2.3, 4.5 (and infinity) are used as the upper bounds for its four bins. For the second input variable x1, 3.1, 5 (and infinity) are used as the upper bounds for its three bins.
Output 5.4.1 shows the "Bin Details" table.
Output 5.4.1: Bin Details
| Bin Details | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| Variable | Bin ID | Lower Bound | Upper Bound | Bin Width | Number of Observations | Mean | Standard Deviation | Minimum | Maximum |
| x2 | Missing | 0 | |||||||
| 1 | -Infty | 2 | 1 | 1 | 1 | 1 | |||
| 2 | 2 | 2.3000 | 0.3000 | 1 | 2 | 2 | 2 | ||
| 3 | 2.3000 | 4.5000 | 2.2000 | 3 | 4 | 0 | 4 | 4 | |
| 4 | 4.5000 | Infty | 5 | 6.6000 | 0.5477 | 6 | 7 | ||
| x1 | Missing | 1 | |||||||
| 1 | -Infty | 3.1000 | 5 | 2.2000 | 1.3038 | 0 | 3 | ||
| 2 | 3.1000 | 5 | 1.9000 | 1 | 4 | 4 | 4 | ||
| 3 | 5 | Infty | 3 | 5.6667 | 0.5774 | 5 | 6 | ||