BookmarkSubscribeRSS Feed
venkatard
Calcite | Level 5

How to split a dataset 80 - 20 percent with common id  i.e i want to split data by id(80-20percentage of data to be splitted on basis of id)

id      score    forum

12     89          98    

12     87          67    

13     56          87    

13     45          98    

14     78          98

15    23           87    

16    54          23

3 REPLIES 3
AncaTilea
Pyrite | Level 9

Hi,

Given the example you provided, how do you want the end result to look like?

Thanks.

DBailey
Lapis Lazuli | Level 10

Presuming that you want all of the records associated with 80% of unique IDs to be identified:

data have;

input id score forum;

cards;

12     89          98   

12     87          67   

13     56          87   

13     45          98   

14     78          98

15    23           87   

16    54          23

;

proc sql;

create table ids as select distinct id, 0 as id_rand_val from work.have order by id;

update ids set id_rand_val=rand('uniform');

create table want as

select

    t1.*,

    case when t2.id_rand_val <= .8 then 'Group1' else 'Group2' end as ID_Group

from

    work.have t1

    inner join work.ids t2

        on t1.id=t2.id;

quit;

data_null__
Jade | Level 19

SELECTED=1 is the RATE= sample in this case the 20%.  Therefore SELECTED=0 would be the 1-rate part.

data score;
   input id $     score    forum;
   cards;
12     89          98    
12     87          67    
13     56          87    
13     45          98    
14     78          98
15    23           87    
16    54          23
;;;;
   run;
proc surveyselect seed=2 rate=.2 outall;
  
SAMPLINGUNIT id;
   run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 3 replies
  • 3645 views
  • 1 like
  • 4 in conversation