BookmarkSubscribeRSS Feed
Jeff_DOC
Pyrite | Level 9

Good afternoon.

 

I'm hoping someone out there can help me with proc surveyselect. I have a dataset of multiple locations and within each location are multiple caseloads. What I need is to randomly select 1 case from each caseload to a maximum selection of 11 per audit location. If there are more caseloads than 11 in the audit location I just want a random selection of 11 even if that means not selecting a case from one caseload. If there are less than 11 caseloads for a location I need as many cases from each caseload to get to 11. I've read the documentation and read over the boards and some answers can just about get me there but not quite.

 

I am using Enterprise Guide version 7.15 HF2

 

Thank you for any help you can provide.

 

Here's one of the many iterations I've tried and a file attachment for practice

 

proc surveyselect data = have01

stats

n = 1

out = want01

sampsize = 11

selectall;

 

/* method=sys*/

/* n=11;*/

/* control caseload;*/

strata audit_location caseload ;

run;

 

2 REPLIES 2
cau83
Pyrite | Level 9

Here's a data step solution. The first sort and original_order variable are just to demonstrate that it's randomly sampling. First, add a random number to each record. Then sort by audit location and the random order. The second data step will keep the first 11 of that random number.

 

proc sort data=example_1;
by audit_location;
data sample;
set example_1;
by audit_location;
if first.audit_location=1 then original_order=1;
else original_order+1;
random=ranuni(12345);
run;

proc sort data=sample;
by audit_location random;
data sample2;
set sample;
by audit_location;
if first.audit_location=1 then sample_count=1;
else sample_count+1;
if sample_count gt 11 then delete;
run;
Jeff_DOC
Pyrite | Level 9

Thank you very much. I really appreciate it.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1313 views
  • 0 likes
  • 2 in conversation