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 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; samp=1; *indicator variable for subject in the sample; DROP rn seed1 i; OUTPUT; END; LABEL rn="Random uniform number between 0 and 10: RN" numb="Integer part of RN: NUMB" n="Randomly selected subject number: N" samp="Subject in Sample: SAMP";   ********************************************; *** List the subjects selected in the sample; ********************************************; PROC PRINT LABEL; 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 ; 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 ; 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 pop2; BY n;   PROC PRINT DATA=d1 LABEL; TITLE2 "Table 4. Listing of the Population with Identified Sample";     *******************************************; *** Merge the population and sample data *; *** and print the results *; *** Delete those not in the sample *; *******************************************; DATA d2; MERGE s1 pop2; BY n; IF samp NE 1 THEN DELETE;   PROC PRINT DATA=d2 LABEL; TITLE2 "Table 5. Listing of the Sample Subjects"; RUN;