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;
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)
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.
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)
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.