In R,the {stats} or the {coin} package can be used to calculate McNemar. The {coin} package has the same defaults as SAS. But, using either of these packages, the first step is to calculate a frequency table, using the table function.
The FREQ procedure can be used in SAS with the AGREE option to run the McNemar test. Note that the OR, and RISKDIFF options can produce odds ratios and risk difference, but they are not estimates of paired contrasts so bear no relation to the McNemar test. Details of confidence intervals for paired binomial contrasts that are consistent with the McNemar test can be found here. They can be produced in SAS with the %PAIRBINCI macro available from https://github.com/petelaud/ratesci-sas, and in R with ratesci::scorepairci(), both of which provide the p-value along with the CI.
In contrast to R, SAS outputs the Kappa coefficients with confident limits as default.
proc freqdata=colds;tables age12*age14 / agree or riskdiff;run;
Summary and Recommendation
When calculating the odds ratio and risk difference confidence limits, SAS is not treating the data as matched-pairs. There is advice on the SAS blog and SAS support page to amend this, which requires a lot of additional coding.
{stats} is using Edward’s continuity correction by default, but this can be removed. In contrast, there is no option to include Edward’s continuity correction in SAS, but this can be manually coded to agree with R. However, its use is controversial due to being seen as overly conservative.
There is another R package that is sometimes used to calculate McNemar’s, called epibasix. This package is no longer being maintained, and there was no documentation available for certain methods used. Therefore, the use of the epibasix package is advised against and other packages may be more suitable.
NoteSession Info
─ Session info ───────────────────────────────────────────────────────────────
setting value
version R version 4.5.2 (2025-10-31)
os Ubuntu 24.04.4 LTS
system x86_64, linux-gnu
ui X11
language (EN)
collate C.UTF-8
ctype C.UTF-8
tz UTC
date 2026-07-10
pandoc 3.8.3 @ /opt/quarto/bin/tools/ (via rmarkdown)
─ Packages ───────────────────────────────────────────────────────────────────
! package * version date (UTC) lib source
P coin * 1.4-3 2023-09-27 [?] RSPM (R 4.5.0)
[1] /home/runner/work/CAMIS/CAMIS/renv/library/linux-ubuntu-noble/R-4.5/x86_64-pc-linux-gnu
[2] /opt/R/4.5.2/lib/R/library
P ── Loaded and on-disk path mismatch.
─ External software ──────────────────────────────────────────────────────────
setting value
SAS 9.04.01M7P080520
──────────────────────────────────────────────────────────────────────────────