BINNING Procedure
Bucket Binning
(View the complete code for this example.)
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.
The following DATA step creates the data table mylib.bucket, which consists of 1,000 observations of an ID variable (id) and three continuous variables (x1–x3), in your CAS session:
data mylib.bucket;
length id 8;
call streaminit(12345);
do id=1 to 1000;
x1 = rand("Uniform");
x2 = rand("Uniform") * 10;
x3 = rand("Uniform") * 100;
output;
end;
run;
These statements assume that your CAS engine libref is named mylib, but you can substitute any appropriately defined CAS engine libref.
The following statements show how you can use the BINNING procedure to perform bucket binning:
proc binning data=mylib.bucket numbin=10 method=bucket;
input x1-x3;
output out=mylib.out;
run;
The DATA= option specifies the input data table. The NUMBIN= option requests that 10 bins be created for all binning variables. The METHOD= option requests that the bucket binning method be used. The INPUT statement names three continuous variables (x1–x3) as input variables for binning. The OUTPUT statement creates an OUTPUT data table to contain the results of PROC BINNING.
Figure 1 displays the "Bin Details" table. This table shows the binning variable, bin ID, bin lower bound, bin upper bound, bin width, number of observations in that bin, and some statistics of that bin (such as mean, standard deviation, minimum, and maximum).
Figure 1: Bin Details
| Bin Details | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| Variable | Bin ID | Lower Bound | Upper Bound | Bin Width | Number of Observations | Mean | Standard Deviation | Minimum | Maximum |
| x1 | Missing | 0 | |||||||
| 1 | -Infty | 0.1004 | 97 | 0.0553 | 0.0279 | 0.0005 | 0.0985 | ||
| 2 | 0.1004 | 0.2003 | 0.0999 | 106 | 0.1490 | 0.0296 | 0.1006 | 0.1980 | |
| 3 | 0.2003 | 0.3002 | 0.0999 | 92 | 0.2497 | 0.0267 | 0.2012 | 0.2987 | |
| 4 | 0.3002 | 0.4001 | 0.0999 | 99 | 0.3529 | 0.0266 | 0.3024 | 0.3993 | |
| 5 | 0.4001 | 0.5000 | 0.0999 | 89 | 0.4422 | 0.0288 | 0.4007 | 0.4995 | |
| 6 | 0.5000 | 0.5998 | 0.0999 | 107 | 0.5437 | 0.0286 | 0.5002 | 0.5931 | |
| 7 | 0.5998 | 0.6997 | 0.0999 | 95 | 0.6471 | 0.0294 | 0.6013 | 0.6961 | |
| 8 | 0.6997 | 0.7996 | 0.0999 | 93 | 0.7521 | 0.0300 | 0.7003 | 0.7984 | |
| 9 | 0.7996 | 0.8995 | 0.0999 | 101 | 0.8446 | 0.0272 | 0.8010 | 0.8994 | |
| 10 | 0.8995 | Infty | 121 | 0.9452 | 0.0288 | 0.8997 | 0.9994 | ||
| x2 | Missing | 0 | |||||||
| 1 | -Infty | 1.0044 | 97 | 0.4827 | 0.2799 | 0.0057 | 0.9973 | ||
| 2 | 1.0044 | 2.0031 | 0.9987 | 104 | 1.5221 | 0.2821 | 1.0067 | 1.9993 | |
| 3 | 2.0031 | 3.0018 | 0.9987 | 111 | 2.5116 | 0.2972 | 2.0079 | 2.9934 | |
| 4 | 3.0018 | 4.0006 | 0.9987 | 95 | 3.5063 | 0.2880 | 3.0024 | 3.9980 | |
| 5 | 4.0006 | 4.9993 | 0.9987 | 91 | 4.4807 | 0.3002 | 4.0113 | 4.9960 | |
| 6 | 4.9993 | 5.9980 | 0.9987 | 77 | 5.5351 | 0.2816 | 5.0104 | 5.9959 | |
| 7 | 5.9980 | 6.9967 | 0.9987 | 100 | 6.5170 | 0.2783 | 6.0154 | 6.9882 | |
| 8 | 6.9967 | 7.9954 | 0.9987 | 111 | 7.4421 | 0.2722 | 7.0002 | 7.9516 | |
| 9 | 7.9954 | 8.9941 | 0.9987 | 110 | 8.4127 | 0.2815 | 8.0026 | 8.9929 | |
| 10 | 8.9941 | Infty | 104 | 9.5013 | 0.2805 | 9.0124 | 9.9928 | ||
| x3 | Missing | 0 | |||||||
| 1 | -Infty | 10.192 | 101 | 4.8474 | 3.1068 | 0.2160 | 10.190 | ||
| 2 | 10.192 | 20.167 | 9.9757 | 94 | 14.880 | 2.9955 | 10.211 | 20.084 | |
| 3 | 20.167 | 30.143 | 9.9757 | 104 | 25.173 | 3.0393 | 20.207 | 30.141 | |
| 4 | 30.143 | 40.119 | 9.9757 | 85 | 34.993 | 2.9221 | 30.542 | 40.059 | |
| 5 | 40.119 | 50.095 | 9.9757 | 95 | 44.885 | 3.0297 | 40.312 | 49.732 | |
| 6 | 50.095 | 60.070 | 9.9757 | 104 | 54.577 | 2.8664 | 50.097 | 59.895 | |
| 7 | 60.070 | 70.046 | 9.9757 | 94 | 64.963 | 2.7889 | 60.139 | 69.596 | |
| 8 | 70.046 | 80.022 | 9.9757 | 124 | 75.166 | 2.6515 | 70.065 | 79.945 | |
| 9 | 80.022 | 89.998 | 9.9757 | 85 | 84.991 | 2.8269 | 80.142 | 89.789 | |
| 10 | 89.998 | Infty | 114 | 94.853 | 2.9066 | 90.046 | 99.973 | ||