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

Say I want to select a random sample of 5 car makes (out of the total of 38 different makes) from sashelp.cars and pull all records sharing one of the randomly select 5 car makes.

 

I've tried the following but it returns an error message. 

 

How do you perform random sampling of records by variable value?

 

proc sort data=sashelp.cars; by make; run;
proc surveyselect data=sashelp.cars out=work.cars_samp seed=123 method=srs n=5; strata make; run; ERROR: The sample size, 5, is greater than the number of sampling units, 1. NOTE: The above message was for the following stratum: Make=Hummer. ERROR: The sample size, 5, is greater than the number of sampling units, 2. NOTE: The above message was for the following stratum: Make=Isuzu. ERROR: The sample size, 5, is greater than the number of sampling units, 3. NOTE: The above message was for the following stratum: Make=Jeep. ERROR: The sample size, 5, is greater than the number of sampling units, 3. NOTE: The above message was for the following stratum: Make=Land Rover. ERROR: The sample size, 5, is greater than the number of sampling units, 2. NOTE: The above message was for the following stratum: Make=MINI. ERROR: The sample size, 5, is greater than the number of sampling units, 3. NOTE: The above message was for the following stratum: Make=Oldsmobile. ERROR: The sample size, 5, is greater than the number of sampling units, 2. NOTE: The above message was for the following stratum: Make=Scion. NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.CARS_SAMP may be incomplete. When this step was stopped there were 155 observations and 17 variables. WARNING: Data set WORK.CARS_SAMP was not replaced because this step was stopped.
1 ACCEPTED SOLUTION

Accepted Solutions
SAS_Rob
SAS Employee

Putting MAKE on the CLUSTER statement will have it select 5 different makes, keeping all the observations in each make.

 

proc surveyselect data=sashelp.cars
out=work.cars_samp
seed=123
method=srs
n=5;
cluster make;
run;
proc freq data=work.cars_samp;
tables make;
run;

View solution in original post

2 REPLIES 2
SAS_Rob
SAS Employee

Putting MAKE on the CLUSTER statement will have it select 5 different makes, keeping all the observations in each make.

 

proc surveyselect data=sashelp.cars
out=work.cars_samp
seed=123
method=srs
n=5;
cluster make;
run;
proc freq data=work.cars_samp;
tables make;
run;

PGStats
Opal | Level 21

Select the makes, then extract the sample:

 

proc sql;
create table makes as
select unique make from sashelp.cars; 
quit;
 
proc surveyselect data=makes n=5 out=makes_5 seed=123; run;

proc sql;
create table cars_samp as
select *
from sashelp.cars
where make in (select make from makes_5);
drop table makes_5;
quit;
PG

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!
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
  • 2 replies
  • 1808 views
  • 5 likes
  • 3 in conversation