OPTIONS LINESIZE=88 PAGESIZE=53 NOCENTER NODATE NONUMBER NOFMTERR; *************************************************************************; * PROJECT NAME: Selecting Samples without Replacement in SAS ; * PROGRAM NAME DATE PROGRAMMER ; TITLE1 "Source:lec25p2.sas C:\ed\web\be691f\webready 12/2/98 EJS " ; * Description: Select a simple random sample of size 5 with ; * replacement from a population of size N=10 ; * and combine the results with the population ; *********************************************************************; **************************************; *** Select a simple random sample of ; *** 5 observations with replacement ; *** from the numbers 1-10 ; **************************************; DATA s1; seed1=3362; DO i=1 TO 5; rn=RANUNI(seed1)*10; numb=INT(rn); n=numb+1; DROP rn seed1 ; OUTPUT; END; LABEL rn="Random uniform number between 0 and 10: RN" numb="Integer part of RN: NUMB" n="Randomly selected subject number: N"; ********************************************; *** List the subjects selected in the sample; ********************************************; PROC PRINT LABEL; ID i; TITLE2 "Table 1. List of Sample of n=5 Subjects"; *************************************; *** Read in population data **; *** and list the population **; *************************************; DATA pop1; INPUT id name $ age; CARDS; 4 Mary 24 9 Jill 24 11 Henry 33 22 Peter 34 35 James 33 26 Joe 22 7 Sam 22 48 Linda 25 19 Samantha 27 10 Jesse 31 ; PROC PRINT ; ID id; TITLE2 "Table 2. Listing of the Population"; ******************************************; *** Create a common variable name to link ; *** the sample and population ; *** First, sort the population in some ; *** unique way ; ******************************************; PROC SORT DATA=pop1; BY id; DATA pop2; SET pop1; n=_N_; * use automatic SAS variable _N_; LABEL n="Population Subject number: N"; PROC PRINT ; ID n; TITLE2 "Table 3. Listing of the Population with Assigned Numbers"; *******************************************; *** Arrange the population and sample data ; *** in increasing order of n ; *******************************************; PROC SORT DATA=pop2; BY n; PROC SORT DATA=s1; BY n; *******************************************; *** Merge the population and sample data *; *** and print the results *; *******************************************; DATA d1; MERGE s1 ( IN=insamp DROP=i numb) pop2; BY n; IF insamp; DROP n; PROC PRINT DATA=d1 LABEL; ID id; TITLE2 "Table 4. Listing of the Identified Sample"; RUN;