BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
emery049
Calcite | Level 5

Hello,

 

I'm using the margins macro in SAS 9.4 to calculate risk differences. My model is looking at changes in pre-pregnancy overweight and obesity (ovob) over time (time) as a function of rurality status (rural). The outcome of pre-pregnancy overweight and obesity (ovob) is dichotomous, rurality status (rural) is also dichotomous, and the time variable has 4 levels. I am currently able to get risk differences for the main effects of rurality status and time by listing them separately in the "margins" statement. However, I'm not sure how to get risk differences for the interaction time (rural*time). Any guidance would be much appreciated! I've copied my code below. 

 

 

%Margins(data = wicmarg,

class = rural time,

response = ovob,

roptions = event='1' ,

model = rural time rural*time,

dist = binomial,

margins = rural,

options = atmeans cl diff reverse);

run;

1 ACCEPTED SOLUTION

Accepted Solutions
StatDave
SAS Super FREQ

Getting margins for an interaction means getting margins for each of the combinations of levels of the interacting variables. You can do that by simply specifying the interaction in margins=

%Margins(data = wicmarg,
         class = rural time,
         response = ovob,
         roptions = event='1' ,
         model = rural time rural*time,
         dist = binomial,
         margins = rural*time,
         options = atmeans cl diff reverse)

View solution in original post

4 REPLIES 4
StatDave
SAS Super FREQ

Getting margins for an interaction means getting margins for each of the combinations of levels of the interacting variables. You can do that by simply specifying the interaction in margins=

%Margins(data = wicmarg,
         class = rural time,
         response = ovob,
         roptions = event='1' ,
         model = rural time rural*time,
         dist = binomial,
         margins = rural*time,
         options = atmeans cl diff reverse)
emery049
Calcite | Level 5

Thanks for your response, Dave! I should have mentioned that I had already tried entering the interaction term in the "margins=" statement. When I do that, I get the following error:

 

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
operand is required. The condition was: &margins ne

I don't believe the "*" is allowed in this statement. Any other thoughts on how to get around this would be greatly appreciated.

StatDave
SAS Super FREQ

That code works fine for me using the current release of the Margins macro - v1.08. 

emery049
Calcite | Level 5

Turns out I was using an older version of the macro 😶 Now that I use v1.08, it seems to be running just fine. Thanks again for your help with this!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 523 views
  • 2 likes
  • 2 in conversation