/* recreate error using small data set - ERROR: "STRATUM;" is not a valid name */
Data salestest;
INPUT Id mos stratum sales;
Datalines;
1 61650 1 50008
2 4106 1 5961
3 46306 1 45934
4 54200 1 59255
5 4303 1 3677
6 88352 2 94847
7 108773 2 146875
8 68071 2 65862
9 105970 2 120426
10 85778 2 72323
11 303422 3 322022
12 303962 3 369277
;
run;
proc print data=salestest;
run;
proc Freq data=salestest;
table stratum;
run;
proc surveyselect data=salestest
method=srs n=2
seed=1953 out=sample1;
run;
proc print data=sample1;
run;
proc surveyselect data=salestest
method = srs n=10 seed=1953 out=sample2;
strata stratum;
run;
/* Error:
The table "WORK.SAMPLE2" cannot be opened because it does not contain any columns.
*/
You raised N to 10, which requires 10 observations per stratum. Evidently your data set doesn't contain that many.
Thanks for catching that. That did reproduce the error I am facing with the large data file I am working with.
I am trying to understand the strata statement. If I can run proc frequency using the column name why does it not work with the strata statement as the documentation suggests it should.
title 'Simple Random Sampling';
proc surveyselect data=industry2
method=srs n=15
seed=1953 out=nostratasample;
run;
/*above code works on data read from a file */
proc Freq data=industry2;
table stratum;
run;
/*code above produced output that showed 10 blank rows but had 373 rows in 5 strata */
title 'Stratified Sampling equal allocation';
proc surveyselect data=industry2
method = srs n=10 seed=1953 out=propsample;
strata stratum;
run;
/* code shown above produces the error reproduced in the small sample*/
Try sorting the data by stratum before calling proc surveyselect.
I tried it and had not worked. I went back to basics using the SASHELP data and got it to work. That should help me find out what is going on. Just sharing that code. Once I figure it out, I'll share it.
Data Mybweight;
set sashelp.bweight;
run;
proc sort Data=Mybweight;
by MomEdLevel;
run;
proc boxplot data = Mybweight;
plot Weight * MomEdLevel;
run;
/* create a set for strata totals for surveymeans */
data strattot;
input MomEdLevel _total_;
cards; /* indicates that datalines follow */
0 17449
1 12129
2 12449
3 7973
;
proc surveymeans data=Mybweight total = strattot nobs mean sum clm clsum ;
stratum MomEdLevel ;
var Weight ;
run;
proc surveyselect data=mybweight out=srssamplebwt method=srs n=100 ;
run;
proc surveyselect data=mybweight out=propsamplebwt method=srs samprate=(0.4,0.25,0.25,0.1) seed=91118;
strata MomEdLevel;
run;
proc print data=propsamplebwt(obs=10);
run;
proc freq data=propsamplebwt;
TABLES MomEdLevel;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.