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

Good afternoon.

 

I've posed this question before but can't seem to get a resolution to my dilemma. What I have is a list of locations with groups of caseload numbers within those locations. A caseload number can be repeated within a location a random number of times. What I need is a random selection of caseload numbers from within each location. Each location must have 11 total selections and each caseload must have at least one selection. So basically the strata are location and caseload and the n required are 11 and 1. I cannot figure out how to make this two step stratification selection.

 

If there a fewer than 11 selections in the location strata I need them all as long as I get one from each caseload. If there are more than 11 possible selections in the location strata I only need 11 total but 1 from each caseload. There are fewer than 11 caseloads in each location.

 

Can anyone assist me?

 

Thank you.

 

Code example:

proc surveyselect data = have01

out = want01

selectall

n = (11 1)

method=srs;

strata audit_location caseload;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

I can't see how to do this with proc surveyselect. You could however use this quick method:

 

data have;
call streaminit(96688);
infile "&sasforum\datasets\surveyselect_test_file.txt" firstobs=2 dlm='09'x;
input location :$12. caseload $;
id = _n_;              /* Identify each obs */
rnd = rand("uniform"); /* Assign a random number to each obs */ 
run;

proc sort data=have; by location caseLoad rnd; run;

proc rank data=have out=ordered;
by location caseload;
var rnd;
ranks rndRank;
run;

proc sort data=ordered; by location rndRank rnd; run;

data want;
set ordered;
by location;
if first.location then count = 0;
count + 1;
if count <= 11;
keep id location caseload; 
run;

proc sort data=want; by location caseload id; run;

proc print; run;
PG

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

I will try to propose something that works for your data if you post it as a text file.

PG
Jeff_DOC
Pyrite | Level 9

Thank you so much for the assist.

 

Does this attachment help?

PGStats
Opal | Level 21

I can't see how to do this with proc surveyselect. You could however use this quick method:

 

data have;
call streaminit(96688);
infile "&sasforum\datasets\surveyselect_test_file.txt" firstobs=2 dlm='09'x;
input location :$12. caseload $;
id = _n_;              /* Identify each obs */
rnd = rand("uniform"); /* Assign a random number to each obs */ 
run;

proc sort data=have; by location caseLoad rnd; run;

proc rank data=have out=ordered;
by location caseload;
var rnd;
ranks rndRank;
run;

proc sort data=ordered; by location rndRank rnd; run;

data want;
set ordered;
by location;
if first.location then count = 0;
count + 1;
if count <= 11;
keep id location caseload; 
run;

proc sort data=want; by location caseload id; run;

proc print; run;
PG
Jeff_DOC
Pyrite | Level 9

That works! Thank you so much. This is a great lesson for me to be wary of "tunnel vision". I focused so much on surveyselect I neglected to entertain other possible solutions.

 

Thanks so much!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1672 views
  • 1 like
  • 2 in conversation