Programming the statistical procedures from SAS

proc surveyselect double stratification

Accepted Solution Solved
Reply
Contributor
Posts: 56
Accepted Solution

proc surveyselect double stratification

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;


Accepted Solutions
Solution
‎03-29-2018 05:56 PM
Esteemed Advisor
Posts: 5,532

Re: proc surveyselect double stratification

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


All Replies
Esteemed Advisor
Posts: 5,532

Re: proc surveyselect double stratification

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

PG
Contributor
Posts: 56

Re: proc surveyselect double stratification

Thank you so much for the assist.

 

Does this attachment help?

Solution
‎03-29-2018 05:56 PM
Esteemed Advisor
Posts: 5,532

Re: proc surveyselect double stratification

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
Contributor
Posts: 56

Re: proc surveyselect double stratification

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!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 144 views
  • 0 likes
  • 2 in conversation