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

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;

panel1.png

Failed attempt at all-at-once:

proc surveyfreq data=gender_ly;
   	strata strata;
	weight nationalweight;
	tables sport_name*injsite/  or;
run;

panel2.png

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
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?

View solution in original post

12 REPLIES 12
Reeza
Super User
You want to add a BY statement. You want it for each Site, not by site.

proc surveyfreq data=gender_LY;
by injsite;
strata strata;
weight nationalweight;
tables sport_name/ or;
run;
tburus
Obsidian | Level 7

This is what I get when I run that code (repeats for each injury site). No odds ratios print out.

plot.png

Reeza
Super User
Try adding the INJSITE to the table statement as well.
tburus
Obsidian | Level 7

SAS is not happy with injsite being in both the BY and TABLES statements.

SteveDenham
Jade | Level 19

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

tburus
Obsidian | Level 7

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?

Reeza
Super User
Ah...you're testing each sub population against the rest of the population so that won't work. You don't have a ton of observations (800) so making a big table against all is probably a decent option. To store tables look at the ODS statement and then the PERSIST option if you want to loop through and keep that in the data.
tburus
Obsidian | Level 7

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  
Reeza
Super User
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?

tburus
Obsidian | Level 7

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.

Reeza
Super User

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

SteveDenham
Jade | Level 19

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

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
  • 12 replies
  • 1578 views
  • 1 like
  • 3 in conversation