Sample 24763: Stratified random sample without replacement, unequal allocation
Select a random sample of data where the number of observations
chosen from each group are of different sizes, without replacement.
Note: Method 1 uses PROC SURVEYSELECT which is part of the SAS/STAT
package in Version 7 and above. If you do not have SAS/STAT
licensed or if you are running Version 6 of SAS, see Method 2.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
/* Create sample data base of student grade point averages from */
/* East High School, Grades 9 through 12, 100 or more students per grade. */
data EastHigh;
format GPA 3.1;
do Grade=9 to 12;
do StudentID=1 to 100+int(201*ranuni(432098));
GPA=2.0 + (2.1*ranuni(34280));
output;
end;
end;
run;
/* Method 1: Using PROC SURVEYSELECT */
/* */
/* Sample 1% of Grade 9 and 5% from all other grades. Rate is the */
/* percentage of observations to select from each group. Use METHOD=SRS. */
/* The statement STRATA defines the variable that is used for grouping. */
/* OUT= names the SAS data set that will be created by the procedure. */
proc surveyselect data=EastHigh method=srs
rate=(.01, .05, .05, .05) out=sample;
strata Grade;
run;
title 'Method 1: PROC SURVEYSELECT';
proc print data=sample;
run;
/* Method 2: Using Base SAS */
/* */
/* Count the number of observations per BY-Group and store the */
/* result in variable N. Input the percentage of observations */
/* to randomly select for each unique value of the BY-Group. */
/* Create K to hold the actual number of observations that */
/* will be selected from each BY-Group. */
data nselect;
set EastHigh(keep=Grade);
by Grade;
n+1;
if last.Grade;
input num;
k=ceil(n*(num/100));
output;
n=0;
datalines;
1
5
5
5
;
/* K contains the number of observations yet to be selected, */
/* N contains the number of observations that remain in the group. */
/* K is decremented each time an observation is selected, N is */
/* decremented on each iteration of the DATA step. */
data sample2(drop= k n num);
merge EastHigh nselect;
by Grade;
if ranuni(12345)<=k/n then do;
output;
k=k-1;
end;
n=n-1;
run;
title 'Method 2: Using Base SAS ';
proc print data=sample2;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Method 1: PROC SURVEYSELECT 14:27 Thursday, November 4, 2004 156
Student Number Expected Sampling
Obs Grade GPA ID Hits Hits Weight
1 9 3.9 10 1 0.010274 97.3333
2 9 2.8 208 1 0.010274 97.3333
3 9 2.7 257 1 0.010274 97.3333
4 10 3.8 13 1 0.050000 20.0000
5 10 3.1 22 1 0.050000 20.0000
6 10 2.1 25 1 0.050000 20.0000
7 10 3.2 27 1 0.050000 20.0000
8 10 2.4 48 1 0.050000 20.0000
9 10 2.9 66 1 0.050000 20.0000
10 11 3.5 26 1 0.054217 18.4444
11 11 3.2 33 2 0.054217 18.4444
12 11 2.6 41 1 0.054217 18.4444
13 11 2.7 42 1 0.054217 18.4444
14 11 3.2 69 1 0.054217 18.4444
15 11 2.7 140 1 0.054217 18.4444
16 11 3.2 155 1 0.054217 18.4444
17 11 2.6 160 1 0.054217 18.4444
18 12 2.1 15 1 0.053812 18.5833
19 12 4.1 22 1 0.053812 18.5833
20 12 2.5 77 1 0.053812 18.5833
21 12 3.3 88 1 0.053812 18.5833
22 12 2.8 116 1 0.053812 18.5833
23 12 4.1 119 1 0.053812 18.5833
24 12 2.1 136 1 0.053812 18.5833
25 12 4.0 169 1 0.053812 18.5833
26 12 3.2 172 1 0.053812 18.5833
27 12 4.0 181 1 0.053812 18.5833
28 12 3.7 200 1 0.053812 18.5833
29 12 2.8 202 1 0.053812 18.5833
Method 2: Using Base SAS 14:27 Thursday, November 4, 2004 158
Student
Obs GPA Grade ID
1 2.3 9 151
2 2.7 9 166
3 4.0 9 212
4 2.6 10 11
5 2.6 10 20
6 3.9 10 33
7 3.1 10 56
8 2.9 10 83
9 3.5 10 92
10 2.7 11 42
11 2.6 11 55
12 2.5 11 70
13 4.0 11 83
14 2.4 11 85
15 4.1 11 104
16 2.2 11 151
17 3.2 11 155
18 2.1 11 166
19 2.9 12 10
20 3.5 12 43
21 3.6 12 55
22 2.7 12 62
23 2.8 12 71
24 2.7 12 89
25 2.4 12 125
26 4.0 12 127
27 4.0 12 181
28 3.9 12 190
29 2.5 12 196
30 2.2 12 205
Select a random sample of data where the number of
observations chosen from each group are of different
sizes, without replacement.
| Type: | Sample |
| Topic: | Analytics ==> Survey Sampling and Analysis SAS Reference ==> Procedures ==> SURVEYSELECT SAS Reference ==> DATA Step
|
| Date Modified: | 2006-04-29 03:02:58 |
| Date Created: | 2004-09-30 14:09:11 |
Operating System and Release Information
| SAS System | SAS/STAT | All | n/a | n/a |
| SAS System | Base SAS | All | n/a | n/a |