Solved
Contributor
Posts: 56

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

run;

Accepted Solutions
Solution
‎03-29-2018 05:56 PM
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;
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;
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;
run;

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

proc print; run;``````
PG

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