OPTIONS LINESIZE=88 PAGESIZE=53 NOCENTER NODATE NONUMBER NOFMTERR; *************************************************************************; * PROJECT NAME: Selecting Samples without Replacement in SAS ; * PROGRAM NAME DATE PROGRAMMER ; TITLE1 "Source:lec25p5.sas C:\ed\web\be691f\webready 12/3/98 EJS " ; * Description: Select a simple random sample of size 5 WITHOUT ; * replacement from a population of size N=10 ; * repeat this selection many times, and tabulate the proportion of ; * times each subject will have been selected ; *************************************************************************; **************************************************; *** Generate multiple populations of the same size; *** ID numbers ; **************************************************; DATA d; %LET popn=1000; *number of populations; %LET n=10; * subjects in population; %LET ssize=5; * sample size without replacement; DO pop=1 to &popn; DO id=1 TO &n; OUTPUT; END; END; PROC PRINT; WHERE pop LE 2; ID pop; BY pop; TITLE2 "Table 5.1. List of &popn populations each of size=&n"; **************************************; *** Select a simple random sample ; *** 5 observations without ; *** replacement ; *** from each population of 10 numbers; **************************************; DATA d2; SET d; BY pop; IF FIRST.pop THEN DO; npop=&n; nsamp=&ssize; END; RETAIN npop nsamp ; prob=nsamp/npop; *proportion of observations left to select; rn=RANUNI(3362); *random number to see if current obs is selected; IF rn LT prob THEN DO; insamp=1; *indicator for values selected in the sample; nsamp=nsamp-1; *number left to select in the sample; OUTPUT; END; npop=npop-1; ****************************************; *** Summarize the frequency of sample selections; ****************************************; PROC FREQ DATA=d2; TABLES id; TITLE2 "Table 5.2. Frequency of Subjects Selected via "; TITLE3 " Simple Random Sampling without Replacement"; TITLE4 " from &popn populations each with &n subjects with samples of size &ssize"; RUN;