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);
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.
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:
@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);
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);
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.
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);
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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.