BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
John4
Obsidian | Level 7

I'm using SAS to do machine learning. I would like to randomly split my data into 60% training, 20% validation, and 20% test data sets. How do I do that in SAS?

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

There are many ways. Here is one:

 

data training validation test;
  set sashelp.class;
  _n_=rand('uniform');
  if _n_ le .6 then output training;
  else if _n_ le .8 then output validation;
  else output test;
run;

Art, CEO, AnalystFinder.com

View solution in original post

4 REPLIES 4
art297
Opal | Level 21

There are many ways. Here is one:

 

data training validation test;
  set sashelp.class;
  _n_=rand('uniform');
  if _n_ le .6 then output training;
  else if _n_ le .8 then output validation;
  else output test;
run;

Art, CEO, AnalystFinder.com

Reeza
Super User

Are you using SAS EM? If so, check the Partition task. 

Ksharp
Super User
Or PROC SURVEYSELECT.


%let dsid=%sysfunc(open(sashelp.class));
%let nobs=%sysfunc(attrn(&dsid,nlobs));
%let dsid=%sysfunc(close(&dsid));

%let train=%sysevalf(0.6*&nobs,int);
%let valid=%sysevalf(0.2*&nobs,int);
%let test=%eval(&nobs-&train-&valid);

%put &train &valid &test;

proc surveyselect data=sashelp.class group=(&train &valid &test) out=want;
run;

data train valid test;
 set want;
 select(groupid);
 when(1) output train;
 when(2) output valid;
 when(3) output test;
 otherwise;
 end;
run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 2274 views
  • 3 likes
  • 4 in conversation