BINNING Procedure
Example 5.1 Quantile Binning
(View the complete code for this example.)
The following DATA step generates 1,000,000 observations of an ID variable (id) and two continuous variables (x1–x2). The mylib CAS library reference enables your client machine to communicate with the CAS session. These statements assume that your CAS engine libref is named mylib, but you can substitute any appropriately defined CAS engine libref.
data mylib.ex1;
length id 8;
call streaminit(12345);
do id=1 to 1000000;
x1 = rand("Uniform");
x2 = rand("Uniform") * 10;
output;
end;
run;
The following statements demonstrate how to use PROC BINNING to perform the quantile binning:
proc binning data=mylib.ex1 numbin=10 method=quantile;
input x1-x2;
output out=mylib.out1;
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 quantile binning method be used. The INPUT statement names two continuous variables (x1–x2) as input variables for binning. The OUTPUT statement creates an OUTPUT data table to contain the results of PROC BINNING.
The "Bin Details" table in Quantile Binning 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). When the binning method is quantile, PROC BINNING assigns the same number of observations to each bin for the input variables if possible.
Output 5.1.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.0995 | 99999 | 0.0497 | 0.0288 | 795E-9 | 0.0995 | ||
| 2 | 0.0995 | 0.1998 | 0.1003 | 100000 | 0.1496 | 0.0289 | 0.0995 | 0.1998 | |
| 3 | 0.1998 | 0.2999 | 0.1001 | 100000 | 0.2498 | 0.0289 | 0.1998 | 0.2999 | |
| 4 | 0.2999 | 0.3997 | 0.0998 | 100000 | 0.3498 | 0.0289 | 0.2999 | 0.3997 | |
| 5 | 0.3997 | 0.4999 | 0.1002 | 100000 | 0.4497 | 0.0290 | 0.3997 | 0.4999 | |
| 6 | 0.4999 | 0.5997 | 0.0998 | 100000 | 0.5498 | 0.0288 | 0.4999 | 0.5997 | |
| 7 | 0.5997 | 0.6994 | 0.0997 | 100000 | 0.6495 | 0.0287 | 0.5997 | 0.6994 | |
| 8 | 0.6994 | 0.7996 | 0.1002 | 100000 | 0.7495 | 0.0289 | 0.6994 | 0.7996 | |
| 9 | 0.7996 | 0.8999 | 0.1003 | 100000 | 0.8497 | 0.0290 | 0.7996 | 0.8999 | |
| 10 | 0.8999 | Infty | 100001 | 0.9499 | 0.0289 | 0.8999 | 1.0000 | ||
| x2 | Missing | 0 | |||||||
| 1 | -Infty | 1.0047 | 99999 | 0.5034 | 0.2895 | 975E-8 | 1.0047 | ||
| 2 | 1.0047 | 2.0057 | 1.0011 | 100000 | 1.5041 | 0.2889 | 1.0047 | 2.0057 | |
| 3 | 2.0057 | 3.0011 | 0.9954 | 100000 | 2.5054 | 0.2874 | 2.0057 | 3.0011 | |
| 4 | 3.0011 | 4.0050 | 1.0039 | 100000 | 3.5041 | 0.2898 | 3.0011 | 4.0050 | |
| 5 | 4.0050 | 5.0069 | 1.0019 | 100001 | 4.5051 | 0.2891 | 4.0050 | 5.0069 | |
| 6 | 5.0069 | 6.0046 | 0.9977 | 99999 | 5.5068 | 0.2882 | 5.0069 | 6.0046 | |
| 7 | 6.0046 | 7.0039 | 0.9993 | 99999 | 6.5056 | 0.2884 | 6.0046 | 7.0039 | |
| 8 | 7.0039 | 7.9989 | 0.9950 | 100001 | 7.5002 | 0.2870 | 7.0039 | 7.9989 | |
| 9 | 7.9989 | 9.0017 | 1.0028 | 100000 | 8.5010 | 0.2898 | 7.9989 | 9.0016 | |
| 10 | 9.0017 | Infty | 100001 | 9.5010 | 0.2881 | 9.0017 | 10.000 | ||