BookmarkSubscribeRSS Feed
adityaa9z
Obsidian | Level 7

Hi all, 

 

I want to understand how can I split a dataset into multiple datasets in different percentages. 

 

Say I have a dataset Have and I want to split it into first  20% and rest equally into 3 parts.

 

Thanks in advance 

5 REPLIES 5
andreas_lds
Jade | Level 19

I am sure that this question was asked many times before and almost always somebody answered: "why? Splitting data is a good idea in very, very few cases, only."

 

Some hints:

  • the set-statement has the options "nobs" - useful to know how many obs are in a dataset
  • the automatic variable _n_ is necessary to trigger the right output-statement
  • because the output-statement does not allow dynamic naming of the dataset to write to, you have to code one output-statement for each dataset to be created
  • each dataset has to be named in the data-statement
PeterClemmensen
Tourmaline | Level 20

I agree with @andreas_lds, hardly ever a good idea.

 

However if you want to do it anyways, here is a nice example of how

 

Creating Quantile Groups

RW9
Diamond | Level 26 RW9
Diamond | Level 26

First off, its generally better to not do so, assigning groups within the one dataset creates easier programming down the line.

If you wish to continue then surveyselect should be able to do it:

https://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#surveyselect_toc.h...

 

Which was mentioned in:

https://communities.sas.com/t5/Base-SAS-Programming/Subsetting-Dataset-based-on-number-of-observatio...

PaigeMiller
Diamond | Level 26

I feel like joining the party!

 

Don't split your data sets!

 

 

--
Paige Miller
Ksharp
Super User
data x1 x2 x3 x4;
 set sashelp.air;
 call streaminit(123456789);
 _id_=rand('table',0.2,0.8/3,0.8/3);
 if _id_=1 then output x1;
  else if _id_=2 then output x2;
    else if _id_=3 then output x3;
      else if _id_=4 then output x4;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1876 views
  • 0 likes
  • 6 in conversation