OPTIONS LINESIZE=88 PAGESIZE=53 NOCENTER NODATE NONUMBER NOFMTERR; *************************************************************************; * PROJECT NAME: Learning to Use SAS ; * PROGRAM NAME DATE PROGRAMMER ; TITLE1 "Source:lec24p5.sas C:\ed\web\be691f\webready 11/30/98 EJS " ; * Description: Program simulates 200 selections of a sample of n=7 from a ; * binomial distribution with n=7, p=.2, and compares it with a ; * similar normal distribution with meand 0.2, and var 0.2(0.8)/7 ; * INPUT: none ; ** Output: none ; *************************************************************************; ***********************************; *** Generate 7 binomial RV and ; *** estimate sample proportion ; ***********************************; DATA d; ***************************; *** Define macro variable *; *** for probability of ill; ***************************; %LET p=0.2; %LET n=7; %LET ntrials=2000; DO I=1 to &ntrials; x_m=RANBIN(3333,7,&p)/&n; LABEL x_m= 'Sample proportion'; OUTPUT; END; PROC CHART; HBAR x_m /TYPE=PERCENT MIDPOINTS=-.25 TO 0.65 BY 0.05; TITLE2 "Figure 4.1. Percent Frequency of Mean from Sample of N=7 from population with P=&p"; TITLE3 " based on &ntrials trials"; *****************************************; *** Use Normal random number generator to; *** get sample of 200 observations from a ; *** normal distribution with mean 0.20 ; *** VAR= p(1-p)/n =0.2(0.8)/7=0.22857 ; *** SE=0.151 ; *** And plot histogram ; *****************************************; DATA d2; DO i=1 to &ntrials; phat= &p + SQRT(&p*(1-&p)/&n)*RANNOR(223); OUTPUT; END; PROC CHART; HBAR phat /TYPE=PERCENT MIDPOINTS=-.25 TO 0.65 BY 0.05; TITLE2 "Figure 4.2. Chart of &ntrials random variables from a Normal Distribution mean=&p, SE=0.151"; RUN;