/******************************************** Macro to conduct hypothesis test for difference of two proportions. INPUT: o y1,y2: number having characteristic in samples 1 and 2 o n1,n2: sample size, samples 1 and 2 o delta0, the difference p1-p2 under H0 OUTPUT: o Value of test statistic (z0, if delt0=0; z, otherwise) o Pvalues: p+, p- and p+- *********************************************/ %macro bi2test(y1,n1,y2,n2,delta0); %let a=%sysevalf(&delta0,boolean); %if &a=0 %then %goto second; data bi_test2; p1hat=&y1/&n1; p2hat=&y2/&n2; se=sqrt(p1hat*(1-p1hat)/&n1+p2hat*(1-p2hat)/&n2); z=(p1hat-p2hat-&delta0)/se; p_minus=cdf('normal',z,0,1); p_plus=1-cdf('normal',z,0,1); p_plus_minus=2*min(p_minus,p_plus); run; proc print noobs; var z p_minus p_plus p_plus_minus; run; %goto last; %second: data bi_test2; p1hat=&y1/&n1; p2hat=&y2/&n2; phat=(&y1+&y2)/(&n1+&n2); se=sqrt(phat*(1-phat)*(1/&n1+1/&n2)); z0=(p1hat-p2hat)/se; p_minus=cdf('normal',z0,0,1); p_plus=1-cdf('normal',z0,0,1); p_plus_minus=2*min(p_minus,p_plus); run; proc print noobs; var z0 p_minus p_plus p_plus_minus; run; %last: %mend bi2test; /******************************************** Sample call using numbers from examples in lecture notes: %bi2test(24,200,26,100,0); %bi2test(24,200,26,100,-0.1); *********************************************/