BookmarkSubscribeRSS Feed
Ayan_Patel
Calcite | Level 5

I have to run K-fold validation and i am writing a code in SAS node for creating 10 folds.

Code is as below:

data MyLib.selection;
call streaminit(12345);
set &em_import_data;
urand=rand('uniform');
proc sort data=MyLib.selection;
by urand;
data &em_export_train;
drop fold_size urand;
set MyLib.selection NOBS=nobs_;
fold_size=round(nobs_/10);
if _N_<= fold_size then fold='A';
if _N_> fold_size and _N_<=2*foold_size then fold='B';
if _N_ >2*fold_size and _N_<=3*fold_size then fold='C';
if _N_ >3*fold_size and _N_<=4*fold_size then fold='D';
if _N_ >4*fold_size and _N_<=5*fold_size then fold='E';
if _N_ >5*fold_size and _N_<=6*fold_size then fold='F';
if _N_ >6*fold_size and _N_<=7*fold_size then fold='G';
if _N_ >7*fold_size and _N_<=8*fold_size then fold='H';
if _N_ >8*fold_size and _N_<=9*fold_size then fold='I';
if _N_ >9*fold_size then fold='J';
proc means data=&em_export_train;
by fold;
run;

 

 

 

But I am getting this error :

ERROR: Write access to member EMWS1.EMCODE_TRAIN.DATA is denied

ERROR: Data set EMWS1.EMCODE_TRAIN is not sorted in ascending sequence. The current BY group has fold = A and the next BY group has fold = ''.

 

1 REPLY 1
WendyCzika
SAS Employee

When I tried your code, I only got the 2nd error, and to fix that, you just need to add a PROC SORT before the PROC MEANS:

 

proc sort data=&em_export_train;

   by fold;

run;

 

Not sure why you would be getting the write access error.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 740 views
  • 0 likes
  • 2 in conversation