BookmarkSubscribeRSS Feed
Xiaoyi
Obsidian | Level 7

Dear SAS Masters, 

 

I have a data (just a sample) like the following (real data have more variables). I want to calculate Odds Ratios (OR) and 95% CI using logistic regression models adjusting several other factors . Because I need to do it for more 100 variables, that means I will have to build more 100 + logistic models and then pick the OR and 95% from the results and then put in my report. 

 

Does any master here have good solution that can put the outputs of many logistic models together in one or fewer tables? I can write Macro to deal with repeated logistic regression, but I am scratching my head for having to put these results all together. Only OR and 95%CI, whether they are together or separate, with or without other outputs, doesn't matter, as long as they can be aggregated in one table, that could save me tons of work. Thanks in advance if you could offer some programming tips. 

Joy

 

 Adjusted variables (co-variance): Adjust1 Adjust2

Var1-Var4 compared between Group using logistic regression

Group=1 as reference group, Group 2, Group 3 are all compared to Group 1, so the odds ratios are for 1 vs 2, 1 vs 3, etc

 

ID  Adjust1  Adjust2  Var1  Var2  Var3  Var4  Group

01    1            23          1        2       2        1        3

02    2            40           2       1       2        2         1

03    1             20          2        2      2        1         2

04     2            35          1         1      2        2        3

 

6 REPLIES 6
Xiaoyi
Obsidian | Level 7

 

Dear SAS Masters, 

 

I have a data (just a sample) like the following (real data have more variables). I want to calculate Odds Ratios (OR) and 95% CI using logistic regression models adjusting several other factors . Because I need to do it for more 100 variables, that means I will have to build more 100 + logistic models and then pick the OR and 95% from the results and then put in my report. 

 

Does any master here have good solution that can put the outputs of many logistic models together in one or fewer tables? I can write Macro to deal with repeated logistic regression, but I am scratching my head for having to put these results all together. Only OR and 95%CI, whether they are together or separate, with or without other outputs, doesn't matter, as long as they can be aggregated in one table, that could save me tons of work. Thanks in advance if you could offer some programming tips. 

(Sorry if you see this as repeated question, I am just trying to find a solution for an urgent report. )

Joy   

 

 Adjusted variables (co-variance): Adjust1 Adjust2

Var1-Var4 compared between Group using logistic regression

Group=1 as reference group, Group 2, Group 3 are all compared to Group 1, so the odds ratios are for 1 vs 2, 1 vs 3, etc

 

ID  Adjust1  Adjust2  Var1  Var2  Var3  Var4  Group

01    1            23          1        2       2        1        3

02    2            40           2       1       2        2         1

03    1             20          2        2      2        1         2

04     2            35          1         1      2        2        3

Rick_SAS
SAS Super FREQ

When you say "more than 100 variables," do you mean that there are 100 responses and the explanatory effects for each model are the same? For example, do the models look something like

Y1 = X1-X4;

Y2 = X1-X4;

...

Y100 = X1-X4;

 

If so, look transposing the data to long form and using BY-group analysis. The odds ratios and CIs will automatically appear in the same output table. For details, see "An easy way to run thousands of regressions in SAS."

Xiaoyi
Obsidian | Level 7

Dear SAS Masters, 

 

I have a data (just a sample) like the following (real data have more variables). I want to calculate Odds Ratios (OR) and 95% CI using logistic regression models adjusting several other factors . Because I need to do it for more 100 variables, that means I will have to build more 100 + logistic models and then pick the OR and 95% from the results and then put in my report. 

 

Does any master here have good solution that can put the outputs of many logistic models together in one or fewer tables? I can write Macro to deal with repeated logistic regression, but I am scratching my head for having to put these results all together. Only OR and 95%CI, whether they are together or separate, with or without other outputs, doesn't matter, as long as they can be aggregated in one table, that could save me tons of work. Thanks in advance if you could offer some programming tips. 

Joy

 

 Adjusted variables (co-variance): Adjust1 Adjust2

Var1-Var4 compared between Group using logistic regression

Group=1 as reference group, Group 2, Group 3 are all compared to Group 1, so the odds ratios are for 1 vs 2, 1 vs 3, etc

 

ID  Adjust1  Adjust2  Var1  Var2  Var3  Var4  Group

01    1            23          1        2       2        1        3

02    2            40           2       1       2        2         1

03    1             20          2        2      2        1         2

04     2            35          1         1      2        2        3

Reeza
Super User

Search on lexjansen.com for sample code. Though to be honest, I've found manipulating other peoples macros more difficult that writing my own from scratch. You may find a perfect example though...

 

Because I need to do it for more 100 variables, that means I will have to build more 100 + logistic models and then pick the OR and 95% from the results and then put in my report. 

 

Another option is to reformat your data somehow so you can use BY group processing, this isn't always possible. 

 

If you need further help, I suggest you post sample data as a data step and what you want as output. Anything you have so far is helpful as well.

 


@Xiaoyi wrote:

Dear SAS Masters, 

 

I have a data (just a sample) like the following (real data have more variables). I want to calculate Odds Ratios (OR) and 95% CI using logistic regression models adjusting several other factors . Because I need to do it for more 100 variables, that means I will have to build more 100 + logistic models and then pick the OR and 95% from the results and then put in my report. 

 

Does any master here have good solution that can put the outputs of many logistic models together in one or fewer tables? I can write Macro to deal with repeated logistic regression, but I am scratching my head for having to put these results all together. Only OR and 95%CI, whether they are together or separate, with or without other outputs, doesn't matter, as long as they can be aggregated in one table, that could save me tons of work. Thanks in advance if you could offer some programming tips. 

Joy

 

 Adjusted variables (co-variance): Adjust1 Adjust2

Var1-Var4 compared between Group using logistic regression

Group=1 as reference group, Group 2, Group 3 are all compared to Group 1, so the odds ratios are for 1 vs 2, 1 vs 3, etc

 

ID  Adjust1  Adjust2  Var1  Var2  Var3  Var4  Group

01    1            23          1        2       2        1        3

02    2            40           2       1       2        2         1

03    1             20          2        2      2        1         2

04     2            35          1         1      2        2        3


 

Reeza
Super User
Note that I've merged your posts as they are identical.
StatDave
SAS Super FREQ

You don't need a macro. Simply use the PERSIST option in an ODS OUTPUT statement to accumulate tables across multiple procedure runs.  For example, these statements save two tables across both procedure runs in the two named data sets:

ods output FitStatistics(persist)=fs ModelInfo(persist)=mf;
proc logistic data=ingots;
model r/n=heat;
run;
proc logistic data=ingots;
model r/n=soak;
run;
ods output close;

Find the name of the table you want to keep in the "Details: ODS Table Names" section of the PROC LOGISTIC documentation. You might also want to use the ODDSRATIO statement in PROC LOGISTIC to generate the odds ratios. Again, see the PROC LOGISTIC documentation.

 

Also see this note for how to easily fit a series of models in separate procedure runs using a different predictor in each model.

 

However, note that if you run a bunch of separate models, the odds ratios you obtain for a particular predictor are only adjusted for the other predictors in the individual model. Any predictors that you want *adjusted* odds ratios for must have all of the predictors you want to adjust for in the model. 

sas-innovate-2024.png

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.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 2107 views
  • 5 likes
  • 4 in conversation