Data Preparation

Page 349

A.10 Analysis of Nominal and Ordinal Variables

A.10.2 Macro PropDiff() %macro PropDiff(ContTable, Xvar, Yvar, Alpha, M_Prop, M_Upper, M_Lower); /* Calculation of the proportion difference and its confidence interval */ /* Sig=Significance level (1-alpha/2) % */ /* Sort the contingency table by the categories of the Xvar */ proc sort data=&ContTable; by &Xvar &Yvar; run; /* Convert the entries n_ij of the contingency table into macro variables as: Y1 Y2 X1 N1 N2 X2 N3 N4 */ data _NULL_; set &ContTable; call symput ("n_"||left(_N_), COUNT); run; /* calculate N1* , N2*, P1, P2 */ %let N1star=%eval(&N_1+&N_2); %let N2star=%eval(&N_3+&N_4); %let P1=%sysevalf(&N_1/&N1star); %let P2=%sysevalf(&N_3/&N2star); /* Calculate |P1-P2| (absolute value of the difference) */ %let P1P2=%sysfunc(abs(&p1-&P2)); /* Substitute in the formula for Sigma(P1-P2) */ %let sigma=%sysfunc(sqrt(((&P1*(1-&P1))/&N1star)+ ((&P2*(1-&P2))/&N2star))); /* Store proportion difference, upper and lower limits in their return variables. */ %let &M_Prop = &P1P2; %let &M_Upper=%sysevalf(&p1p2 + &sigma * %sysfunc(probit(1-&alpha/2))); %let &M_Lower=%sysevalf(&p1p2 - &sigma * %sysfunc(probit(1-&alpha/2))); %mend;

353


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.