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-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!

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.

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