I've seen instructions for how to overlay ROC curves when the outcome is the same across models but not when they're different. For example, is it possible to overlay these two ROC curves that have the same predictors but different outcomes?
*Make example dataset;
data test ( keep = anemia allergy weight visit );
set sashelp.bweight;
if _N_ <= 100;
anemia = black;
allergy = married;
run;
*Outcome = ANEMIA;
proc logistic data = test descending;
model anemia = weight visit;
roc weight visit;
run; quit;
*Outcome = ALLERGY;
proc logistic data = test descending;
model allergy = weight visit;
roc weight visit;
run; quit;
Use the OUTROC= option on the MODEL statement to output the points for each ROC curve. Merge the two curves. Use SGPLOT to overlay the two curves:
*Make example dataset;
data test ( keep = anemia allergy weight visit );
set sashelp.bweight;
if _N_ <= 100;
anemia = black;
allergy = married;
run;
*Outcome = ANEMIA;
proc logistic data = test descending;
model anemia = weight visit / outroc=ROC1;
run; quit;
*Outcome = ALLERGY;
proc logistic data = test descending;
model allergy = weight visit / outroc=ROC2;
run; quit;
/* merge in the population ROC curve */
data ROCAll;
set ROC1(in=r1) ROC2;
if r1 then Model=1;
else Model = 2;
run;
title "Compare ROC Curves for Different Models";
proc sgplot data=ROCAll aspect=1 noautolegend;
step x=_1MSPEC_ y=_SENSIT_ / group=Model;
lineparm x=0 y=0 slope=1 / lineattrs=(color=gray);
xaxis grid; yaxis grid;
label _1MSPEC_ ="False Positive Rate (FPR)" _SENSIT_ ="True Positive Rate (TPR)";
run;
Use the OUTROC= option on the MODEL statement to output the points for each ROC curve. Merge the two curves. Use SGPLOT to overlay the two curves:
*Make example dataset;
data test ( keep = anemia allergy weight visit );
set sashelp.bweight;
if _N_ <= 100;
anemia = black;
allergy = married;
run;
*Outcome = ANEMIA;
proc logistic data = test descending;
model anemia = weight visit / outroc=ROC1;
run; quit;
*Outcome = ALLERGY;
proc logistic data = test descending;
model allergy = weight visit / outroc=ROC2;
run; quit;
/* merge in the population ROC curve */
data ROCAll;
set ROC1(in=r1) ROC2;
if r1 then Model=1;
else Model = 2;
run;
title "Compare ROC Curves for Different Models";
proc sgplot data=ROCAll aspect=1 noautolegend;
step x=_1MSPEC_ y=_SENSIT_ / group=Model;
lineparm x=0 y=0 slope=1 / lineattrs=(color=gray);
xaxis grid; yaxis grid;
label _1MSPEC_ ="False Positive Rate (FPR)" _SENSIT_ ="True Positive Rate (TPR)";
run;
data test ( keep = anemia allergy weight visit ); set sashelp.bweight; if _N_ <= 100; anemia = black; allergy = married; run; ods select none; *Outcome = ANEMIA; proc logistic data = test descending ; model anemia = weight visit/outroc=roc1; ods output Association=Association1; run; *Outcome = ALLERGY; proc logistic data = test descending ; model allergy = weight visit/outroc=roc2; ods output Association=Association2; run; ods select all; proc sql noprint; select cValue2 into :auc1 from Association1 where Label2='c'; select cValue2 into :auc2 from Association2 where Label2='c'; quit; data roc; set roc1 roc2 indsname=dsn; model=scan(dsn,-1,'.'); run; proc sgplot data=roc aspect=1; series x=_1MSPEC_ y=_SENSIT_/group=model; lineparm x=0 y=0 slope=1/lineattrs=(color=verylightgray); xaxis grid valuesformat=F8.2; yaxis grid valuesformat=F8.2; inset "ROC1=&auc1." "ROC2=&auc2."; run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.