PARTITION Procedure

Example 24.4 k-Fold Partitioning

(View the complete code for this example.)

This example demonstrates how to use PROC PARTITION to perform stratified k-fold partitioning 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 kfold=10 seed=10 nthreads=3;
   by BAD;
   output out=mylib.out5 copyvars=(job reason loan value delinq derog);
run;

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

The KFOLD=10 option requests that the input data be partitioned to 10 equal-size folds within each level of the BY variable BAD. The SEED= option specifies 10 as the random seed to be used in the partitioning process. The OUTPUT statement requests that the sampled data be stored in a table named mylib.out5, and the COPYVARS= option lists the variables to be copied from mylib.hmeq to mylib.out5. The output data table, mylib.out5, includes an indicator that shows which fold each observation is selected to.

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

Output 24.4.1: Frequency Information Table

The PARTITION Procedure

k-Fold Partition Frequency
IndexBADNumber
of Obs
Fold Size 1Fold Size 2Fold Size 3Fold Size 4Fold Size 5Fold Size 6Fold Size 7Fold Size 8Fold Size 9Fold Size 10
004771478477477477477477477477477477
111189119118119119119119119119119119


Output 24.4.2 shows the first 20 output sample observations in mylib.out5; the _Fold_ column shows which fold the observation is selected to.

Output 24.4.2: k-Fold Partitioning Output Data Table

ObsJOBREASONLOANVALUEDELINQDEROG_Fold_
1OtherHomeImp110039025001
2OtherHomeImp130068400205
3OtherHomeImp150016700003
4  1500...3
5OfficeHomeImp17001120000010
6OtherHomeImp170040320007
7OtherHomeImp180057037239
8OtherHomeImp180043034006
9OtherHomeImp200046740205
10SalesHomeImp200062250004
11  2000...6
12OfficeHomeImp200029800102
13OtherHomeImp200055000004
14Mgr 200087400002
15OtherHomeImp210083850103
16OtherHomeImp220034687101
17MgrHomeImp2200102600624
18  2200...5
19OtherHomeImp230040150004
20OfficeHomeImp2300120953004


Last updated: September 22, 2026