Why can't SAS compute McNemar's test when zeros are in a column? I think that it is because SAS doesn't "know" that there are zeros.
For example, consider the following data set for a hypothetical case-control study.
data one;
input caseevent controlevent number;
cards;
0 0 0
0 1 9
1 0 0
1 1 15
;
run;
In this data set, controls are matched to cases. We have 0 case-control pairs where both the case and the control do NOT have the event.
There are 15 pairs where they both have the case.
For discordant pairs, we have 9 instances where the control had an event, and the case did not.
Also, we have 0 instances where the case had an event, and the case did not.
Running PROC FREQ and requesting McNemar test:
proc freq data=one;
tables caseevent*controlevent / agree;
weight number;
exact mcnemar;
run;
We get the appropriate table
But, there is no McNemar test and SAS log gives a NOTE:
So, apparently SAS thinks we are missing data.
I can calculate McNemar test (with or without continuity correction) manually. In this case X2=(|9-0|^2)/9=9 with one degree of freedom.
Or continuity corrected X2=((|9-0|-1)^2)/9=7.1.
But, it there some way to get sas to do this without having to program it? Further, I would prefer the Exact McNemar test. But, maybe I just need to program conditional Binomial tests for this.
You will need to add the ZEROS option to the WEIGHT statement.
proc freq data=one;
tables caseevent*controlevent / agree;
weight number/zeros;
exact mcnemar;
run;
You will need to add the ZEROS option to the WEIGHT statement.
proc freq data=one;
tables caseevent*controlevent / agree;
weight number/zeros;
exact mcnemar;
run;
Thanks, did not know about the zero option. I suppose that if I have raw data, then this is not going to work. I would have to count the observations in each cell first and create a data set with these summary statistics (frequencies). Then, I could use the zero option with the weighted statement.
Yes, with raw data you could assign a count of 1 to each observation and then add an observation with the missing row/column combination and a count of 0.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.