Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Analytics
- /
- Stat Procs
- /
- proc surveyselect double stratification

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 03-29-2018 03:23 PM
(1671 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

4 REPLIES 4

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

PG

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thank you so much for the assist.

Does this attachment help?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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!

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

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.