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

How to randomly select a single measurement of each individuals from a repeated measurement data? My original data is in shape of 'test' and resulting data would look like 'want' except its observations randomly populated.

 

data test;
input ID Age_at_measurement_right	Age_at_measurement_left;
cards;
3232	1.1 1.5
3232	19.3 18.3
3232	33.2 32.1
3236	1.2	1.6
3236	16.2 13.2
3236	23.1 22.1
3266	1.5 1.3
3266	19.3 18.3
3266	33.1 32.3
;

data want;
input ID Age_at_measurement_right	Age_at_measurement_left;
cards; 
3232	19.3	18.3
3236	23.1	22.1
3266	1.5	1.3
;
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Two common approaches:

 

  1. Add a random variable to each observation. 
  2. Sort by group and random value.
  3. Take the first record for each group. 


PROC SURVEYSELECT with N=1 and stratify on GROUP.

View solution in original post

2 REPLIES 2
Reeza
Super User

Two common approaches:

 

  1. Add a random variable to each observation. 
  2. Sort by group and random value.
  3. Take the first record for each group. 


PROC SURVEYSELECT with N=1 and stratify on GROUP.

Cruise
Ammonite | Level 13

@Reeza

Hi Reeza, below code worked out. Please let me know if it looks not quite right. Hope I got it.

 

PROC SURVEYSELECT data=test
method=srs n=1 
seed=1235 out=test_sample;
strata 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
  • 2 replies
  • 526 views
  • 1 like
  • 2 in conversation