OPTIONS LINESIZE=88 PAGESIZE=53 NOCENTER NODATE NONUMBER NOFMTERR; *************************************************************************; * PROJECT NAME: Selecting Samples without Replacement in SAS ; * PROGRAM NAME DATE PROGRAMMER ; TITLE1 "Source:lec25p11.sas C:\ed\web\be691f\webready 12/3/98 EJS " ; * Description: Select stratified sample for Anaconda children with known; * age with constant sampling fraction in each stratum = 0.25 where ; * Strata 1 2 3 4 5 6 ; * Population 32 61 33 34 81 14 ; * Sample 8 15 8 9 20 4 ; * using SRS w/o replacement ; * Input: ANC2V1.sd2 ; * Population data for children from Anaconda, Montana with ; * a subset of the variables ; *************************************************************************; LIBNAME new "c:\temp";   **********************************************; *** Read in Data on Population from Anaconda, ; *** Montana, and select variables of interest; *** Exclude subjects with missing age ; **********************************************;   DATA anc2v1; SET new.anc2v1; IF ageyr=. THEN DELETE;   ***********************************************; *** Sort Subjects by Strata number *; ***********************************************; PROC SORT; BY stratum aid1 aid2;   ************************************************; *** Select the sample for each stratum **; ************************************************; DATA s1; SET anc2v1; BY stratum; ARRAY npop{6} (32 61 33 34 81 14); ARRAY nsamp{6} (8 15 8 9 20 4); **********************************; *** Set population sizes *; **********************************; IF FIRST.stratum THEN DO; pop=npop{stratum}; samp=nsamp{stratum}; END; **********************; *** select sample **; **********************; seed1=1232; RETAIN pop samp ; prob=samp/pop; IF RANUNI(seed1) LT prob THEN DO; samp=samp-1; OUTPUT; END; pop=pop-1; **************************************************; **** List the IDs for the sample Subjects ***; **************************************************; PROC PRINT DATA=s1 ; VAR stratum aid1 aid2 ; TITLE2 "Table 11.1. Simple list of samples"; PROC FREQ; TABLES stratum; TITLE2 "Table 11.2. Summary of sample sizes"; RUN;