PARTITION Procedure
Example 24.3 Oversampling
(View the complete code for this example.)
This example demonstrates how to use PROC PARTITION to perform oversampling; it uses the same data table as in Example 24.1.
You can load the sampsio.hmeq data set into your CAS session by naming your CAS engine libref in the first statement of the following DATA step. This DATA step assumes that your CAS engine libref is named mylib, but you can substitute any appropriately defined CAS engine libref.
data mylib.hmeq;
set sampsio.hmeq;
run;
The following statements perform oversampling:
proc partition data=mylib.hmeq samppctevt=90 eventprop=0.5
event="1" seed=10 nthreads=1;
by BAD;
ods output OVERFREQ=outFreq;
output out=mylib.out4 copyvars=(job loan value delinq derog)
freqname=_Freq2_;
run;
proc print data=mylib.out4(obs=20);
run;
The EVENTPROP=0.5 option specifies that 50% of the sample are rare events. The SAMPPCTEVT=90 option requests that 90% of the rare events be sampled. The EVENT="1" option specifies that the second level of the variable BAD corresponds to a rare event. The OUTPUT statement requests that the sampled data be stored in a table named mylib.out4, specifies the variables to be transferred from the input data table, requests that the _Freq_ column be renamed to _Freq2_.
Output 24.3.1 shows the number of observations in the sample and in each level of the BY variable BAD in the mylib.out4 data table.
Output 24.3.1: Frequency Information Table
| Oversampling Frequency | |||
|---|---|---|---|
| Index | BAD | Number of Obs | Number of Samples |
| 0 | 0 | 4771 | 1070 |
| 1 | 1 | 1189 | 1070 |
Output 24.3.2 shows the first 20 output sample observations in the mylib.out4 data table; the _Freq2_ column shows the ratio of target level’s proportion in the population to its proportion in the sample.
Output 24.3.2: Output Data Table
| Obs | JOB | LOAN | VALUE | DELINQ | DEROG | _Freq2_ |
|---|---|---|---|---|---|---|
| 1 | Other | 1100 | 39025 | 0 | 0 | 0.39899 |
| 2 | Other | 1300 | 68400 | 2 | 0 | 0.39899 |
| 3 | Other | 1500 | 16700 | 0 | 0 | 0.39899 |
| 4 | 1500 | . | . | . | 0.39899 | |
| 5 | Other | 1700 | 40320 | 0 | 0 | 0.39899 |
| 6 | Other | 1800 | 57037 | 2 | 3 | 0.39899 |
| 7 | Other | 1800 | 43034 | 0 | 0 | 0.39899 |
| 8 | Other | 2000 | 46740 | 2 | 0 | 0.39899 |
| 9 | Sales | 2000 | 62250 | 0 | 0 | 0.39899 |
| 10 | 2000 | . | . | . | 0.39899 | |
| 11 | Office | 2000 | 29800 | 1 | 0 | 0.39899 |
| 12 | Other | 2000 | 55000 | 0 | 0 | 0.39899 |
| 13 | Mgr | 2000 | 87400 | 0 | 0 | 1.60101 |
| 14 | Other | 2100 | 83850 | 1 | 0 | 0.39899 |
| 15 | Other | 2200 | 34687 | 1 | 0 | 0.39899 |
| 16 | Mgr | 2200 | 102600 | 6 | 2 | 0.39899 |
| 17 | 2200 | . | . | . | 0.39899 | |
| 18 | Other | 2300 | 40150 | 0 | 0 | 0.39899 |
| 19 | Other | 2300 | 46200 | 1 | 0 | 0.39899 |
| 20 | Mgr | 2400 | 40800 | 0 | 0 | 0.39899 |