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
Type: | Sample |
Topic: | Analytics ==> Survey Sampling and Analysis SAS Reference ==> Procedures ==> SURVEYSELECT SAS Reference ==> DATA Step |
Date Modified: | 2016-01-11 16:08:09 |
Date Created: | 2004-09-30 14:09:11 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | Base SAS | Aster Data nCluster on Linux x64 | ||
DB2 Universal Database on AIX | ||||
DB2 Universal Database on Linux x64 | ||||
Greenplum on Linux x64 | ||||
Netezza TwinFin 32bit blade | ||||
Netezza TwinFin 32-bit SMP Hosts | ||||
Netezza TwinFin 64-bit S-Blades | ||||
Netezza TwinFin 64-bit SMP Hosts | ||||
Teradata on Linux | ||||
z/OS | ||||
z/OS 64-bit | ||||
OpenVMS VAX | ||||
Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
Microsoft Windows XP 64-bit Edition | ||||
Microsoft® Windows® for x64 | ||||
OS/2 | ||||
Microsoft Windows 8 Enterprise 32-bit | ||||
Microsoft Windows 8 Enterprise x64 | ||||
Microsoft Windows 8 Pro 32-bit | ||||
Microsoft Windows 8 Pro x64 | ||||
Microsoft Windows 8.1 Enterprise 32-bit | ||||
Microsoft Windows 8.1 Enterprise x64 | ||||
Microsoft Windows 8.1 Pro | ||||
Microsoft Windows 8.1 Pro 32-bit | ||||
Microsoft Windows 10 | ||||
Microsoft Windows 95/98 | ||||
Microsoft Windows 2000 Advanced Server | ||||
Microsoft Windows 2000 Datacenter Server | ||||
Microsoft Windows 2000 Server | ||||
Microsoft Windows 2000 Professional | ||||
Microsoft Windows NT Workstation | ||||
Microsoft Windows Server 2003 Datacenter Edition | ||||
Microsoft Windows Server 2003 Enterprise Edition | ||||
Microsoft Windows Server 2003 Standard Edition | ||||
Microsoft Windows Server 2003 for x64 | ||||
Microsoft Windows Server 2008 | ||||
Microsoft Windows Server 2008 R2 | ||||
Microsoft Windows Server 2008 for x64 | ||||
Microsoft Windows Server 2012 Datacenter | ||||
Microsoft Windows Server 2012 R2 Datacenter | ||||
Microsoft Windows Server 2012 R2 Std | ||||
Microsoft Windows Server 2012 Std | ||||
Microsoft Windows XP Professional | ||||
Windows 7 Enterprise 32 bit | ||||
Windows 7 Enterprise x64 | ||||
Windows 7 Home Premium 32 bit | ||||
Windows 7 Home Premium x64 | ||||
Windows 7 Professional 32 bit | ||||
Windows 7 Professional x64 | ||||
Windows 7 Ultimate 32 bit | ||||
Windows 7 Ultimate x64 | ||||
Windows Millennium Edition (Me) | ||||
Windows Vista | ||||
Windows Vista for x64 | ||||
64-bit Enabled AIX | ||||
64-bit Enabled HP-UX | ||||
64-bit Enabled Solaris | ||||
ABI+ for Intel Architecture | ||||
AIX | ||||
HP-UX | ||||
HP-UX IPF | ||||
IRIX | ||||
Linux | ||||
Linux for x64 | ||||
Linux on Itanium | ||||
OpenVMS Alpha | ||||
OpenVMS on HP Integrity | ||||
Solaris | ||||
Solaris for x64 | ||||
Tru64 UNIX | ||||
SAS System | SAS/STAT | z/OS | ||
z/OS 64-bit | ||||
OpenVMS VAX | ||||
Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
Microsoft Windows XP 64-bit Edition | ||||
Microsoft® Windows® for x64 | ||||
OS/2 | ||||
Microsoft Windows 8 Enterprise 32-bit | ||||
Microsoft Windows 8 Enterprise x64 | ||||
Microsoft Windows 8 Pro 32-bit | ||||
Microsoft Windows 8 Pro x64 | ||||
Microsoft Windows 8.1 Enterprise 32-bit | ||||
Microsoft Windows 8.1 Enterprise x64 | ||||
Microsoft Windows 8.1 Pro | ||||
Microsoft Windows 8.1 Pro 32-bit | ||||
Microsoft Windows 10 | ||||
Microsoft Windows 95/98 | ||||
Microsoft Windows 2000 Advanced Server | ||||
Microsoft Windows 2000 Datacenter Server | ||||
Microsoft Windows 2000 Server | ||||
Microsoft Windows 2000 Professional | ||||
Microsoft Windows NT Workstation | ||||
Microsoft Windows Server 2003 Datacenter Edition | ||||
Microsoft Windows Server 2003 Enterprise Edition | ||||
Microsoft Windows Server 2003 Standard Edition | ||||
Microsoft Windows Server 2003 for x64 | ||||
Microsoft Windows Server 2008 | ||||
Microsoft Windows Server 2008 R2 | ||||
Microsoft Windows Server 2008 for x64 | ||||
Microsoft Windows Server 2012 Datacenter | ||||
Microsoft Windows Server 2012 R2 Datacenter | ||||
Microsoft Windows Server 2012 R2 Std | ||||
Microsoft Windows Server 2012 Std | ||||
Microsoft Windows XP Professional | ||||
Windows 7 Enterprise 32 bit | ||||
Windows 7 Enterprise x64 | ||||
Windows 7 Home Premium 32 bit | ||||
Windows 7 Home Premium x64 | ||||
Windows 7 Professional 32 bit | ||||
Windows 7 Professional x64 | ||||
Windows 7 Ultimate 32 bit | ||||
Windows 7 Ultimate x64 | ||||
Windows Millennium Edition (Me) | ||||
Windows Vista | ||||
Windows Vista for x64 | ||||
64-bit Enabled AIX | ||||
64-bit Enabled HP-UX | ||||
64-bit Enabled Solaris | ||||
ABI+ for Intel Architecture | ||||
AIX | ||||
HP-UX | ||||
HP-UX IPF | ||||
IRIX | ||||
Linux | ||||
Linux for x64 | ||||
Linux on Itanium | ||||
OpenVMS Alpha | ||||
OpenVMS on HP Integrity | ||||
Solaris | ||||
Solaris for x64 | ||||
Tru64 UNIX |