I have a dataset that utilizes complex sampling to generate weighted injury counts across multiple sports. I am wanting to compare relative risk for boys' and girls' versions of the same sport, and do so across multiple variables, such as injury site. I can program SAS to do this one at a time with a dummy variable (see example below) but would like to find a way to run them all at once (no odds ratios print; code from that failed attempt also below).
One-at-a-time:
data gender_ly_hand;
set gender_ly;
if injsite = "Hand/Wrist" then dum = 1;
else dum = 0;
run;
/* this works (column 2 risk), but would have to do for every variable individually */
proc surveyfreq data=gender_ly_hand;
strata strata;
weight nationalweight;
tables sport_name*dum/ or;
run;
Failed attempt at all-at-once:
proc surveyfreq data=gender_ly;
strata strata;
weight nationalweight;
tables sport_name*injsite/ or;
run;
ods output OddsRatio(persist=proc)=odds(where=(Statistic="Column 2 Relative Risk"));
proc surveyfreq data=GLMDesign;
strata strata;
weight nationalweight;
tables col2 * (col4-col15)/ or;
run;
I don't think you needed a macro, you needed the dummy variables though....does the above code work for you as well?
This is what I get when I run that code (repeats for each injury site). No odds ratios print out.
SAS is not happy with injsite being in both the BY and TABLES statements.
To get ORs, you must have at least a 2 way TABLES statement. which is why you get what you want with your original code with the dummy variable. That dummy variable sets hand/wrist as the incidence set and all other sites as the contrafactual set (to steal from the epidemiology nomenclature). You could generate the multiple dummy variables using PROC GLMMOD, and then wrap your SURVEYFREQ code in a short macro loop to step through each of the dummy variables in turn. There might be a way to use a BY statement, but I think you would still need to index the dummy variable to coincide with the BY variable. This might be the rare case where looping would be superior to by processing.
SteveDenham
Okay. So this gets it done (but is a terrible solution from a practical standpoint given what I'm needing it for—don't know that anything can be done about that).
%MACRO DO_LIST;
%DO i = 4 %TO 15;
proc surveyfreq data=GLMDesign;
strata strata;
weight nationalweight;
tables col2*col&i./ or;
run;
%END;
%MEND DO_LIST;
%DO_LIST;
Next, then, would be, how can I get it to capture the column 2 relative risk estimates and CI limits for each iteration of PROC SURVEYFREQ?
So, this works. I kind of hate SAS! Thanks for the help everyone.
%MACRO so_injsite;
ods output OddsRatio(persist=proc)=odds(where=(Statistic="Column 2 Relative Risk"));
%DO i = 4 %TO 15;
proc surveyfreq data=GLMDesign;
strata strata;
weight nationalweight;
tables col2*col&i./ or;
run;
%END;
ods output close;
%MEND so_injsite;
%so_injsite
ods output OddsRatio(persist=proc)=odds(where=(Statistic="Column 2 Relative Risk"));
proc surveyfreq data=GLMDesign;
strata strata;
weight nationalweight;
tables col2 * (col4-col15)/ or;
run;
I don't think you needed a macro, you needed the dummy variables though....does the above code work for you as well?
Yes, this is perfect. I didn't realize I could do this; that's exactly what I was hoping was possible.
Just as a follow up, is that (col4-col15) syntax a standard shorthand in other SAS PROCs for some sort of distributive property on running multiple iterations? That could be helpful elsewhere.
Here is a reference that illustrates how to refer to variables and datasets in a short cut list:
https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html
Hats off to you @Reeza for presenting a simple answer to something I had made more complicated than needed. I wish I could give more than 1 like...
SteveDenham
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.