Building models with SAS Enterprise Miner, SAS Factory Miner, SAS Visual Data Mining and Machine Learning or just with programming

How do i split my dataset into 70% training , 30% testing ?

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

How do i split my dataset into 70% training , 30% testing ?

Dear all ,

I have a dataset in csv format. I am looking for a way/tool to randomly done by dividing 70% of the database for training and 30% for testing , in order to guarantee that both subsets are random samples from the same distribution. I adopt 70% - 30% because it seems to be a common rule of thumb.

Any suggestions / methods / guide ?  or the use of EG ? EM ?

Thank you.


Regards,

YL


Accepted Solutions
Solution
‎07-07-2017 01:53 PM
Respected Advisor
Posts: 4,934

Re: How do i split my dataset into 70% training , 30% testing ?

Simply add

if ranuni() < 0.7 then set="TRAINING";

else set = "TESTING";

to create a new variable as you read your dataset.

PG

PG

View solution in original post


All Replies
Solution
‎07-07-2017 01:53 PM
Respected Advisor
Posts: 4,934

Re: How do i split my dataset into 70% training , 30% testing ?

Simply add

if ranuni() < 0.7 then set="TRAINING";

else set = "TESTING";

to create a new variable as you read your dataset.

PG

PG
Contributor
Posts: 24

Re: How do i split my dataset into 70% training , 30% testing ?

Hi PGStats ,


How could i use the above code to create new varaible ?

Thanks

Respected Advisor
Posts: 4,934

Re: How do i split my dataset into 70% training , 30% testing ?

Those statements would be added to a datastep to create a new character variable called set that would take the value TRAINING randomly for 70% of observations and the value TESTING otherwise.

PG

PG
Contributor
Posts: 71

Re: How do i split my dataset into 70% training , 30% testing ?

Well, if you have EM, then splitting the data into Training and Testing is trivial.  The feature is a default feature when creating your SAS data in EM.  You can also use a Data Partition Node.

Super User
Posts: 5,518

Re: How do i split my dataset into 70% training , 30% testing ?

If you're really interested in splitting a csv file into two csv files, there is no need to create a SAS data set along the way.  Here's one approach:

filename csvfile 'path to existing csv file';

filename train 'path to a training subset';

filename test 'path to a testing subset';

data _null_;

  infile csvfile;

  input @;

  if ranuni(12345) < 0.7 then file train;

  else file test;

   put _infile_;

run;

The drawback is that you will get approximately 70/30, not exact.  If you really want to create a SAS data set from the csv file first, there are many alternatives including PROC SURVEYSELECT.

Good luck.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 4079 views
  • 3 likes
  • 4 in conversation