BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
t75wez1
Pyrite | Level 9

Hi,

I am looking at a survey data set of 694 responses who are in 12 different age groups but the distribution of responses heavily skew to younger age groups.

 

My question is how to randomly select those 694 responses with replacement, but evenly distributed across 12 age groups?

 

Many thanks,

Ethan

 

t75wez1_0-1651347750450.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
t75wez1
Pyrite | Level 9

Hi PGStats,

It works perfectly. Thanks a ton for the sublime solution you provided.

View solution in original post

7 REPLIES 7
PGStats
Opal | Level 21

Use stratified random sampling. Proc surveyselect does that:

 

/* Prepare some test data */
data heart;
set sashelp.heart;
if ageAtDeath > 34;
ageGroup = round(ageAtDeath, 10);
run;

title "Population frequencies";
proc freq data=heart;
table ageGroup;
run;

/* Data must be sorted by strata, prior to random sampling */
proc sort data=heart; by ageGroup; run;

proc surveyselect data=heart sampsize=10 out=sample noprint;
strata ageGroup;
run;

title "Sample frequencies";
proc freq data=sample;
table ageGroup;
run;

PGStats_0-1651351315429.png

 

PG
t75wez1
Pyrite | Level 9

Thanks PGStats, What if I want to have the sample size greater than 20 in "proc surveyselect". so some of responses could be re-selected for certain age groups.

How to make a change in your code below?

 

PGStats
Opal | Level 21

You can request unrestricted random sampling (sampling with replacement) by specifying options METHOD=URS OUTHITS in the proc surveyselect statement. This will allow sampling sizes greater than the strata sizes but will allow replicates in every stratum.

PG
t75wez1
Pyrite | Level 9

Hi PGStats,

It works perfectly. Thanks a ton for the sublime solution you provided.

FreelanceReinh
Jade | Level 19

Hello @t75wez1,

Glad to see that PGStats's solution worked for you. Then it would be fair and help later readers if you marked his helpful reply as the accepted solution, not your own "thank you" post. Could you please change that? It's very easy: Select his post as the solution after clicking "Not the Solution" in the option menu (see icon below) of the current solution.
show_option_menu.png

t75wez1
Pyrite | Level 9

Hello FreelanceRehard,

I got the email stated that "Great job! You marked your answer to a question as an accepted solution!"

and I don't see "Not the solution" option from "Show option menu" you indicated.

Thank you.

 

t75wez1_0-1651502724181.png

 

FreelanceReinh
Jade | Level 19

The item "Not the solution" is only available in the option menu of the current solution (i.e., your post with the green background color).

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Discussion stats
  • 7 replies
  • 945 views
  • 5 likes
  • 3 in conversation