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
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;
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.