![]() | ![]() | ![]() | ![]() | ![]() |
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 have Version 6 of SAS, see Method 2.
Both examples are not included in this section. If you would like to see the examples, please click on the Full Code tab above which is in the same location as the Details, Results, About, and Rate It tabs.
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 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 */
/* */
/* Use METHOD=URS. N= is the number of observations to select. The */
/* sample is stored in the OUT= data set, SAMPLE. */
/* */
/* The OUTHITS option includes an observation in the OUT= data set */
/* for each selected unit. By default, the OUT= will contain one */
/* observation for each unique selected unit and the NumberHits */
/* variable identifies the number of times each unit is selected. */
proc surveyselect data=EastHigh method=urs n=15 out=sample outhits;
run;
title "Method 1: PROC SURVEYSELECT ";
proc print;
run;
/* Method 2: Using SAS DATA Step */
/* */
/* When sampling with replacement, once an obs is selected it goes */
/* back into the pool of possible choices to be selected again. */
/* Instead of reading through the data set sequentially, as in the */
/* Simple random sample without replacement example, use the */
/* POINT= option on the SET statement to read obs directly. */
/* */
/* In the sample below, the variable 'n' is set at compile time. */
/* When the data set header is opened and read, the number of */
/* observations in the data set is assigned to the variable. */
data sample(drop=i);
choice=int(ranuni(36830)*n)+1;
set EastHigh point=choice nobs=n;
i+1;
/* Enter the desired sample size, 15 in this case */
if i>15 then stop;
run;
title "Method 2: DATA step ";
proc print;
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 47
Student Number
Obs GPA Grade ID Hits
1 2.8 9 1 1
2 2.4 9 85 1
3 3.9 9 107 1
4 3.8 9 174 1
5 2.1 9 176 1
6 2.1 10 41 1
7 2.8 10 88 1
8 2.3 10 100 1
9 3.2 10 114 1
10 3.0 11 54 1
11 3.3 11 81 1
12 3.4 12 72 1
13 2.7 12 89 1
14 2.3 12 138 1
15 3.2 12 186 1
Method 2: DATA step 14:27 Thursday, November 4, 2004 48
Student
Obs GPA Grade ID
1 2.8 9 138
2 3.7 10 3
3 3.1 11 12
4 3.6 11 111
5 2.2 11 87
6 4.0 10 97
7 2.3 12 162
8 2.7 9 166
9 3.8 12 155
10 2.7 11 106
11 3.0 10 111
12 2.1 9 122
13 2.8 10 119
14 4.0 10 35
15 2.2 9 152| Type: | Sample |
| Topic: | Analytics ==> Survey Sampling and Analysis SAS Reference ==> Procedures ==> SURVEYSELECT SAS Reference ==> DATA Step |
| Date Modified: | 2010-09-16 12:33:35 |
| Date Created: | 2004-09-30 14:09:15 |
| Product Family | Product | Host | SAS Release | |
| Starting | Ending | |||
| SAS System | SAS/STAT | All | n/a | n/a |
| SAS System | Base SAS | All | n/a | n/a |





