How to export odds ratios, confidence interval and P-value from porc logistic model Macro?

Reply
Contributor
Posts: 27

How to export odds ratios, confidence interval and P-value from porc logistic model Macro?

Hi, 

 

I wrote a macro for univariate logistic regression analysis. How do I export the odds ratio, 95% C.I. and p-value from each of the below model? Should I add ods output statement in the macro? Thank you!  

 

 

%macro CDR_diff(x=);
proc logistic data=cdr_df1;
class &x;
where visitnum=1;
model cdr_dfcat2= &x / expb;
run;
%mend CDR_diff;
%CDR_diff(x=sex);
%CDR_diff(x=ethnic1);
%CDR_diff(x=race1);
%CDR_diff(x=smoke2);
%CDR_diff(x=alcohol1);
%CDR_diff(x=marital1);
%CDR_diff(x=educ1);
%CDR_diff(x=employ1);
%CDR_diff(x=educ_yrs1);
%CDR_diff(x=income1);

PROC Star
Posts: 1,071

Re: How to export odds ratios, confidence interval and P-value from porc logistic model Macro?

Use ODS TRACE on before your PROC LOGISTIC and see what output you want the underlying data from and use ODS OUTPUT on the relevant output.

Super User
Posts: 21,527

Re: How to export odds ratios, confidence interval and P-value from porc logistic model Macro?

 Should I add ods output statement in the macro?

 

Yes, and you should look at the PERSIST option within that. 

 

Here's a very related question that was recently posted:

https://communities.sas.com/t5/SAS-Statistical-Procedures/multiple-logistic-models-output-odds-ratio...

 


Denali wrote:

Hi, 

 

I wrote a macro for univariate logistic regression analysis. How do I export the odds ratio, 95% C.I. and p-value from each of the below model? Should I add ods output statement in the macro? Thank you!  

 

 

%macro CDR_diff(x=);
proc logistic data=cdr_df1;
class &x;
where visitnum=1;
model cdr_dfcat2= &x / expb;
run;
%mend CDR_diff;
%CDR_diff(x=sex);
%CDR_diff(x=ethnic1);
%CDR_diff(x=race1);
%CDR_diff(x=smoke2);
%CDR_diff(x=alcohol1);
%CDR_diff(x=marital1);
%CDR_diff(x=educ1);
%CDR_diff(x=employ1);
%CDR_diff(x=educ_yrs1);
%CDR_diff(x=income1);


 

Contributor
Posts: 27

Re: How to export odds ratios, confidence interval and P-value from porc logistic model Macro?

Hi,

 

I successfully output the odds ratio and confidence interval for the individual model using the "ods output OddsRatios(persist)=Oddsratio ModelInfo(persist)=mf;" statement.

 

But everytime I ran another predictor variable or another model, the odds ratio in the out was replaced. How do I keep all the odds ratios in one output file? For example, I need to run 10 models. How do I keep all 10 odds ratios and confidence intervals in the oddsratio file?

 


ods trace on;
%macro CDR_diff(x=);
ods output OddsRatios(persist)=Oddsratio ModelInfo(persist)=mf;
proc logistic data=cdr_df1;
class &x;
where visitnum=1;
model cdr_dfcat2= &x / expb;
run;
ods output close;
%mend CDR_diff;
%CDR_diff(x=sex);
%CDR_diff(x=ethnic1);
%CDR_diff(x=race1);
%CDR_diff(x=smoke2);
%CDR_diff(x=alcohol1);
%CDR_diff(x=marital1);
%CDR_diff(x=educ1);
%CDR_diff(x=employ1);
%CDR_diff(x=educ_yrs1);
%CDR_diff(x=income1);

Super User
Posts: 21,527

Re: How to export odds ratios, confidence interval and P-value from porc logistic model Macro?

Review the options for PERSIST. 

 

And, have you considered transposing your data and just using a BY with a single PROC LOGISTIC call? Seems more efficient to me.

Contributor
Posts: 27

Re: How to export odds ratios, confidence interval and P-value from porc logistic model Macro?

[ Edited ]

Hi,

 

I tried the transpose statement but it did not work. Could you please check my code? Thank you!


%macro CDR_diff(y=);


ods output OddsRatios(persist)=ORCI ModelInfo(persist)=mf;

 

proc logistic data=cdr_df1;
class &y;
where visitnum=12;
model cdr_dfcat2= &y / expb;
run;

 

proc transpose data=ORCI out=Odds;
by &y;
run;

 

ods output close;
%mend CDR_diff;


%CDR_diff(y=sex);
%CDR_diff(y=ethnic1);

Super User
Posts: 21,527

Re: How to export odds ratios, confidence interval and P-value from porc logistic model Macro?

That's not what I meant. 

 

I mean, transpose your data before the logistic regression and then use a single PROC LOGISTIC. 

 

Here's a blog post that details the approach. 

It's really a better way to go. 

 

https://blogs.sas.com/content/iml/2017/02/13/run-1000-regressions.html

Ask a Question
Discussion stats
  • 6 replies
  • 99 views
  • 1 like
  • 3 in conversation