BookmarkSubscribeRSS Feed
Denali
Quartz | Level 8

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);

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

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.

Reeza
Super User

 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);


 

Denali
Quartz | Level 8

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);

Reeza
Super User

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.

Denali
Quartz | Level 8

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);

Reeza
Super User

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 3091 views
  • 1 like
  • 3 in conversation