PARTITION Procedure

Example 24.2 Stratified Sampling

(View the complete code for this example.)

This example demonstrates how to use PROC PARTITION to perform stratified sampling to partition the data; it uses the same data table as is used 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 the partitioning:

proc partition data=mylib.hmeq samppct=10 samppct2=20 seed=10 partind nthreads=3;
   by BAD;
   output out=mylib.out3 copyvars=(job reason loan value delinq derog);
run;

proc print data=mylib.out3(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 PARTIND option requests that the output data table, mylib.out3, include an indicator that shows whether each observation is selected to a partition (1 for training or 2 for testing) or not (0). The OUTPUT statement requests that the sampled data be stored in a table named mylib.out3, and the COPYVARS= option lists the variables to be copied from mylib.hmeq to mylib.out3.

Output 24.2.1 shows the frequency information for each level of the BY variable BAD in the mylib.out3 data table.

Output 24.2.1: Frequency Information Table

The PARTITION Procedure

Stratified Sampling Frequency
IndexBADNumber
of Obs
Sample
Size 1
Sample
Size 2
004771477954
111189119238


Output 24.2.2 shows the first 20 output sample observations in mylib.out3; the _PartInd_ column shows which partition the observation is selected for (1 for training or 2 for testing) or none (0).

Output 24.2.2: Sample Output with Partition Indicator

ObsJOBREASONLOANVALUEDELINQDEROG_PartInd_
1OtherHomeImp110039025001
2OtherHomeImp130068400200
3OtherHomeImp150016700002
4  1500...2
5OfficeHomeImp1700112000000
6OtherHomeImp170040320000
7OtherHomeImp180057037230
8OtherHomeImp180043034000
9OtherHomeImp200046740200
10SalesHomeImp200062250000
11  2000...0
12OfficeHomeImp200029800102
13OtherHomeImp200055000000
14Mgr 200087400002
15OtherHomeImp210083850102
16OtherHomeImp220034687101
17MgrHomeImp2200102600620
18  2200...0
19OtherHomeImp230040150000
20OfficeHomeImp2300120953000


Last updated: September 22, 2026