BookmarkSubscribeRSS Feed
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


n = 1

out = want01

sampsize = 11



/* method=sys*/

/* n=11;*/

/* control caseload;*/

strata audit_location caseload ;



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;

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;
Pyrite | Level 9

Thank you very much. I really appreciate it.



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 2 in conversation