BookmarkSubscribeRSS Feed
ZhihanZhou
Calcite | Level 5

Hello Everyone,

i want to select 87 samples with following conditions and put all these selected samples into one file:

 

data want;
set have;
if hz='1-7' and zweck=1 then group=1;
else if hz='1-7' and zweck=7 then group=2;
else if hz='3-7' and zweck=3 then group=3;
else if hz='3-7' and zweck=7 then group=4;
else if hz='4-7' and zweck=7 then group=5;
else if hz='5-7' and zweck=7 then group=6;
else if hz='6-7' and zweck=7 then group=7;
else if hz='10-7' and zweck=7 then group=8;
run;
proc surveyselect data=want
method=srs n=87 out=want1 sampsize=(18 6 17 4 10 20 5 7);
strata group;
run;

 

which means, 18 samples from group1, 6 from group2 and so on ......

but it didn't work and comes this warning, but i have already checked the group1 is much more bigger than 7. Could you help me?

 

ZhihanZhou_1-1666364862200.png

 

best wishes,

Zhihan

 

6 REPLIES 6
PaigeMiller
Diamond | Level 26

You are trying to select a random sample of size 18 from a population that has 7 items. This can't be done.

--
Paige Miller
ZhihanZhou
Calcite | Level 5
I have already checked how big is the population, which is much more big than 18, that’s why I don’t know how to correct till it works.
PaigeMiller
Diamond | Level 26

Okay, then read the next error message ...

 

Your data is not sorted properly.

 


@ZhihanZhou wrote:
I have already checked how big is the population, which is much more big than 18, that’s why I don’t know how to correct till it works.

From now on, it would be helpful if you state all the information you have about the problem in your initial message, rather than withholding information about what you have already done.

--
Paige Miller
ZhihanZhou
Calcite | Level 5
Thanks for your reply!
I’ve solved the problem:)
FreelanceReinh
Jade | Level 19

Hello @ZhihanZhou,

 

You must exclude the (seven) observations with missing GROUP values as these would form the first stratum otherwise: Add a WHERE statement

where group>.;

to the PROC SURVEYSELECT step, e.g., before the STRATA statement.

 

If dataset WANT is not yet sorted by GROUP, you need to sort it:

proc sort data=want;
by group;
run;

 

I would also replace the n= option by a SEED= option to specify a random seed so that you can reproduce the sample. SAS ignores the n=87 anyway because you provide stratum sample sizes.

 

Finally, if the error "sample size ... greater than the number of sampling units" still occurs, you can add the SELECTALL option to the PROC SURVEYSELECT statement. Instead of error messages you will then get notes in the log about strata with a smaller sample size than what you specified.

ZhihanZhou
Calcite | Level 5

Hello FreelanceReinhard,

 

thanks very much for your reply! 

i've tried your code besides created a new file, which only has 'group ne .', and it works right now so great, just is what i want!

 

data want;
set have;
if hz='1-7' and zweck=1 then group=1;
if hz='1-7' and zweck=7 then group=2;
if hz='3-7' and zweck=3 then group=3;
if hz='3-7' and zweck=7 then group=4;
if hz='4-7' and zweck=7 then group=5;
if hz='5-7' and zweck=7 then group=6;
if hz='6-7' and zweck=7 then group=7;
if hz='10-7' and zweck=7 then group=8;
run;
data want1;
set want;
where group ne .;
run;
proc sort data=want1;
by group;
run;
proc surveyselect data=1
method=srs sampsize=(18 6 17 4 10 20 5 7) selectall out=want2;
strata group;
run;

Ready to join fellow brilliant minds for the SAS Hackathon?

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

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 715 views
  • 2 likes
  • 3 in conversation