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

Hello, 

 

I have a dataset where individuals have observations across multiple rows. Patients are identified by their ID variable. Can I use proc surveyselect to randomly sample 100 of these unique IDs and then keep all of the rows that are tied to that id? It is almost like cluster sampling where the patient's ID is the cluster and we want to keep all of the individuals in that "cluster". I was having trouble finding anything like this in the documentation for proc surveyselect. If it is not possible to do with surveyselect, how can I do it using a different method (proc sql perhaps)?

 

This is what I've tried. I have also considered trying the selectall option, but that didn't work for me. 

 

proc surveyselect data = data_set method = SRS
  sampsize = 100 seed = 12345 out = sample_ds;
  id _all_;
  strata id;
run;

 

Thank you for any help you can provide!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Watts
SAS Employee

You can use the SAMPLINGUNIT | CLUSTER statement in PROC SURVEYSELECT to select patient IDs instead of observations. For example, add

samplingunit patientID;
proc surveyselect data = data_set method = SRS
  sampsize = 100 seed = 12345 out = sample_ds;
  id _all_;
  strata sart_id;
  samplingunit patientID;
run;

 

View solution in original post

2 REPLIES 2
Watts
SAS Employee

You can use the SAMPLINGUNIT | CLUSTER statement in PROC SURVEYSELECT to select patient IDs instead of observations. For example, add

samplingunit patientID;
proc surveyselect data = data_set method = SRS
  sampsize = 100 seed = 12345 out = sample_ds;
  id _all_;
  strata sart_id;
  samplingunit patientID;
run;

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 2 replies
  • 3161 views
  • 2 likes
  • 2 in conversation