Hi,
I want to get OR for 3 interaction term but SAS is not giving me the output that I am looking for.
Here is the code:
proc logistic data=bp;
class location(ref='1')
mhi_q (ref='4')
lesshs_q (ref='4')
nhwmed_p (ref='2')
nhbmed_p (ref='2')
hispmed_p (ref='2')
/param=ref;
model bpyn(event='1') = location mhi_q lesshs_q nhwmed_p nhbmed_p hispmed_p unemprate HI_rate location*nhwmed_p location*nhbmed_p location*hispmed_p;
oddsratio location/at(nhbmed_p='1' '2') diff=ref;
oddsratio location/at (hispmed_p='1' '2') diff=ref;
oddsratio location/at (nhwmed_p= '1' '2') diff=ref;
run;
This output gives me OR for all 3 race/ethnicity (Black, White, Hispanic) at once for location (rural=0, urban=1). Race/ethnicity is coded as 1 and 2, so all three of them are separate variables. What output I need is like this:
Location 0 vs 1 at NHWMed_P=1 NHWMed_P=2
Location 0 vs 1 at NHBMed_P=1 NHBMed_P=2
Location 0 vs 1 at HispMed_P=1 HispMed_P=2
I have tried changing the codes multiple times, but nothing gives this output. Please help me!
Thanks in advance
I assume what you want is the odds ratio of location for each race. Create just a single, three-level variable for race, rather than three separate variables, then you need only include one interaction for location*race. This should do it.
proc logistic data=bp;
class location(ref='1') mhi_q (ref='4') lesshs_q (ref='4') race / param=ref;
model bpyn(event='1') = location mhi_q lesshs_q race unemprate HI_rate location*race;
oddsratio location;
run;
Then you need to explain much more about the data - particularly these race variables - and a clearer explanation of what precisely you want to estimate.
If I understand your data, each observation is associated with one of two locations and has three variables containing the proportions of the three races (and presumably sum to one). If so, then the following might give you what you want. The trick here is to create a categorical race variable in the model such that it has three levels and therefore three columns in the design matrix, but instead of those columns containing either a 1 or 0 to indicate that the observation belongs entirely to one race, they instead contain the proportions. This can be done using the EFFECT statement to create a collection type of variable. The result is a model with the expected degrees of freedom for the model effects: 1 for location, 2 for race, and 2 for the interaction. You can then use ESTIMATE statements to estimate the log odds for the locations in a given race and the odds ratio (exponentiated difference in log odds) of the locations in that race. For example, assuming you have three race level variables (w, b, h) containing the proportions of each race, the following fits the model and computes the log odds and odds ratio for race=w. The design data set that is created by the OUTDESIGN= option lets you examine the design matrix used to fit the model.
proc logistic data=bp outdesign=od;
class location / param=glm;
effect race=collection(w b h/details);
model y=loc|race;
estimate 'loc 0 race w' intercept 1 loc 1 0 race 1 0 0 loc*race 1 0 0 0 0 0 / ilink;
estimate 'loc 1 race w' intercept 1 loc 0 1 race 1 0 0 loc*race 0 1 0 0 0 0 / ilink;
estimate 'OR loc 0 vs 1 race w' loc 1 -1 loc*race 1 -1 0 0 0 0 / exp;
run;
...but you can also use the ODDSRATIO statement to estimate the odds ratio for each pure race level and that is easier than the ESTIMATE statement:
oddsratio loc / at(w=1 b=0 h=0);
oddsratio loc / at(w=0 b=1 h=0);
oddsratio loc / at(w=0 b=0 h=1);
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.