PARTITION Procedure

Example 24.6 Segment-Stratified Sampling for Each Target Using the FREQ Statement

(View the complete code for this example.)

This example demonstrates how to use PROC PARTITION to perform segment-stratified partitioning for each target with the FREQ statement. 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;
   id = _N_;
   freqVar = 10;
run;

Note that the frequency variable freqVar is set to 10 for all the observations in the hmeq data set in the CAS engine libref mylib.

The following statements perform the partitioning:

proc partition data=mylib.hmeq samppct=10 samppct2=20 seed=10;
   by bad;
   target job reason;
   freq freqVar;
   output out=mylib.out6 copyvars=(job reason loan value delinq derog);
run;

proc print data=mylib.out6(obs=20);
run;

The SAMPPCT=10 option requests that 10% of the input data be included in the training partition, and the SAMPPCT2=20 option requests that 20% of the input data be included in the testing partition. The SEED= option specifies 10 as the random seed to be used in the partitioning process. The BY statement requests that the BY variable bad be used as the segmentation variable. The TARGET statement requests that stratified sampling be performed for each target variable job and reason in each segment level. The FREQ statement requests that the variable freqVar be used as the frequency variable. In this example, the procedure treats each observation as if it appears 10 times. The OUTPUT statement requests that the sampled data be stored in a table named mylib.out6, and the COPYVARS= option lists the variables to be copied from mylib.hmeq to mylib.out6. The output data table, mylib.out6, also includes one partition indicator variable that shows whether each observation is selected for a partition (1 for training, 2 for testing, or 0 for not selected), as well as two sample frequency variables (one for each target variable in each segment level in the BY variable bad).

Output 24.6.1 shows the frequency information for each level combination of the BY variable bad and each target variable in the mylib.out6 data table.

Output 24.6.1: Frequency Information Table

The PARTITION Procedure

Stratified Sampling Frequency
Target NameTarget LevelBADNumber
of Obs
Sample
Size 1
Sample
Size 2
JOB 02560256512
JOBMgr058805881176
JOBOffice082308231646
JOBOther01834018343668
JOBProfExe01064010642128
JOBSales071071142
JOBSelf01350135270
JOB 12302346
JOBMgr11790179358
JOBOffice11250125250
JOBOther155405541108
JOBProfExe12120212424
JOBSales13803876
JOBSelf158058116
REASON 02040204408
REASONDebtCon03183031836366
REASONHomeImp01384013842768
REASON 14804896
REASONDebtCon174507451490
REASONHomeImp13960396792


Output 24.6.2 shows the map of each sample frequency to each target variable.

Output 24.6.2: Sample Frequency Map

Sample Frequency Map
Sample Frequency NameTarget Name
_SampleFreq1_JOB
_SampleFreq2_REASON


Output 24.6.3 shows the first 20 output sample observations in mylib.out6. Each observation is duplicated by three rows in the output, with the _PartInd_ column showing which partition each observation is selected for (1 for training, 2 for testing, or 0 for not selected). The _SampleFreq1_ column shows the sample frequency for each partition for the target variable job. The _SampleFreq2_ column shows the sample frequency for each partition for the target variable reason. Note that the rows for which all the _SampleFreq_ columns have a value of 0 are not included in the output.

Output 24.6.3: Sample Output with Partition Indicator

ObsJOBREASONLOANVALUEDELINQDEROG_PartInd__SampleFreq1__SampleFreq2_
1OtherHomeImp11003902500087
2OtherHomeImp11003902500112
3OtherHomeImp11003902500211
4OtherHomeImp13006840020088
5OtherHomeImp13006840020111
6OtherHomeImp13006840020211
7OtherHomeImp15001670000096
8OtherHomeImp15001670000101
9OtherHomeImp15001670000213
10  1500...096
11  1500...111
12  1500...203
13OfficeHomeImp170011200000088
14OfficeHomeImp170011200000101
15OfficeHomeImp170011200000221
16OtherHomeImp17004032000097
17OtherHomeImp17004032000101
18OtherHomeImp17004032000212
19OtherHomeImp18005703723088
20OtherHomeImp18005703723121


Last updated: September 22, 2026