* Program cnrimacro.v1.sas for BINARY data; * Created by Nancy Cook (BWH, HMS, HSPH); * Macro CNRICAT to compute Adjusted Conditional NRI (CNRI); * For use in intermediate categories of risk; * DETAIL = 2 for detailed output, 1 for limited, 0 for none (eg., to save in a file); * Example Usage: * %cnricat(probs,1,outxy,pdx,pdxy,0.05,0.20,4,0.05,0.10,0.20); ****************************************************************; %macro CNRICAT(DSNAME,DETAIL,STATVAR,PROB1,PROB2,LIM1,LIM2,NCAT,C1,C2,C3,C4,C5); * Macro to compute Conditional NRI (CNRI) adjusted for expected value; * Uses up to 6 categories with cutpoints c1-c5; * Control output of frequency tables and means below; * Variables: * DSNAME = dataset name; * DETAIL = 2 for detailed printout, 1 for limited, 0 for none; * STATVAR = outcome variable (coded 0,1); * PROB1 = probability for model 1; * PROB2 = probability for model 2; * LIM1 AND LIM2 = limits to define the intermediate range; * (Need to equal category cut points); * NCAT = number of categories in classification; * C1-C5 = category cutpoints (should have ncat-1 cutpoints); * Allows up to 6 categories; title2 Adjusted CNRI for &NCAT Categories with CutPoints = %do j = 1 %to &ncat; &&c&j %end; and Limits &lim1 to &lim2; data nri1; set &dsname; * compute diffs in probs; stat=&STATVAR; prob1=&PROB1; prob2=&PROB2; diffp=prob2-prob1; if prob1 ne . and prob2 ne .; * compute categories - set to above cutpoints; * define limits in terms of number of categories; %do i=1 %to &ncat-1; cut&i=&&c&i; %end; cut&ncat=1.01; array cut {6} cut1-cut6; array pcat {6} pcat1-pcat6; if .0 %then %do; proc print data=freqs; title3 "Observed and Expected Freqs"; %end; data cnri; set freqs end=eof; * compute discordance for sequential NRI; retain ncase ncontr encase encontr nup_ca ndn_ca nup_co ndn_co enup_ca endn_ca enup_co endn_co cklim1 cklim2 0; array freq{6,6} f11-f16 f21-f26 f31-f36 f41-f46 f51-f56 f61-f66; array expf{6,6} e11-e16 e21-e26 e31-e36 e41-e46 e51-e56 e61-e66; cklim1=1; cklim2=1; if &lim1=0 then do; int1=1; cklim1=0; end; if &lim2=1 then do; int2=&ncat; cklim2=0; end; %do i=1 %to &ncat-1; if &lim1=&&c&i then do; int1=&i+1; cklim1=0; end; if &lim2=&&c&i then do; int2=&i; cklim2=0; end; %end; * Check category cutpoints; if int1>0 and int2>0 then do; do i=int1 to int2; do j=1 to &ncat; if stat=1 then do; ncase=ncase+freq(i,j); encase=encase+expf(i,j); if j>i then do; nup_ca=nup_ca+freq(i,j); enup_ca=enup_ca+expf(i,j); end; else if ji then do; nup_co=nup_co+freq(i,j); enup_co=enup_co+expf(i,j); end; else if j0 %then %do; proc print data=cnri; title3; run; %end; title2; run; * Usage: * %cnricat(probs,1,outxy,pdx,pdxy,0.05,0.20,4,0.05,0.10,0.20); %exit: %mend CNRICAT; ****************************************************************;