## random selecting cases by stratifying 3 variables (2 binary and one continuous)

Solved
Super Contributor
Posts: 328

# random selecting cases by stratifying 3 variables (2 binary and one continuous)

I need to select 3000 cases from about 63000 cases, by stratefying 3 variables:

age: continuous. what to have similar mean/std in the selected 3000 and the total sample.

gender: binary. want to have similar percentages in the selected 3000 and in the total sample

location: binary. two levels. what to have similar percentage in selected 3000 and in the total.

I am not sure if the following code is right or not. Can I use both categorical and numeric variables for strata ?

```proc surveyselect data = total_sample out = selected_3000
method = srs n=3000 seed = 9876;
strata gender age location;
run;```

Accepted Solutions
Solution
‎09-01-2016 10:18 AM
Posts: 5,543

## Re: random selecting cases by stratifying 3 variables (2 binary and one continuous)

Simple random sampling will give you the correct proportions (gender, location) and average (age) without stratification. Stratification is for when you want your selected sample to represent a population that is not necessarily well represented in your sampling set. Try this:

``````/* Option outall creates a variable named Selected = 1 when selected in the
sample and = 0 otherwise. */
proc surveyselect data = total_sample out = selected_3000
method = srs n=3000 seed = 9876 outall;
run;

/* Check proportions */
proc freq data=selected_3000;
tables selected*(gender location) / chisq;
run;

/* Check age averages */
proc glm data=selected_3000;
class selected;
model age =  selected;
run;``````

(untested)

PG

All Replies
Super User
Posts: 13,583

## Re: random selecting cases by stratifying 3 variables (2 binary and one continuous)

Surveyselect with Strata variables selectes sample size indicated for each level of the strata level. So an actual continuous variable is a poor choice for strata. What is the TOTAL number of records you are trying to select? I can't tell if you want 9000, 15000 or 3000 or something different.

I am not sure what you mean by "in the selected 3000 and the total sample".

You might try leaving out the strata and see if the summary of the resulting data is close enough for your purpose.

Solution
‎09-01-2016 10:18 AM
Posts: 5,543

## Re: random selecting cases by stratifying 3 variables (2 binary and one continuous)

Simple random sampling will give you the correct proportions (gender, location) and average (age) without stratification. Stratification is for when you want your selected sample to represent a population that is not necessarily well represented in your sampling set. Try this:

``````/* Option outall creates a variable named Selected = 1 when selected in the
sample and = 0 otherwise. */
proc surveyselect data = total_sample out = selected_3000
method = srs n=3000 seed = 9876 outall;
run;

/* Check proportions */
proc freq data=selected_3000;
tables selected*(gender location) / chisq;
run;

/* Check age averages */
proc glm data=selected_3000;
class selected;
model age =  selected;
run;``````

(untested)

PG
Super Contributor
Posts: 328

## Re: random selecting cases by stratifying 3 variables (2 binary and one continuous)

The "outall" option is really great. I was thinking to merge back to create such an indicator variable.
☑ This topic is solved.