Hello,
I'm looking to conduct chi square tests for 9 outcome variables each by 29 potential risk factors (i.e., outcome #1 by risk factor #1, then risk factor #2, etc., then outcome #2 by risk factor #1 then risk factor #2, etc.).
So far, I've conceived this piece of code, but I'm not sure how to execute it without somehow attaching numbers to my outcomes and to my risk factors.
%do i=1 to &outcome_&i;
%do j=1 to &rf_&j;
proc freq data=myData ;
table &outcome_&i*&rf_&j/chisq;
run;
%end; /*end risk factor loop*/
%end; /*end outcome loop*/
Thank you for your help.
Try
proc freq data=myData ; table <list of outcome variables * <list of risk variables>j/chisq; run;
When you use a tables statement like
Tables (a b c) * (x y z) you get results for all of the pairs: a*x a*y a*z b*x b*y b*z c*x c*y c*z.
Not sure that by statement in proc freq would work here - wouldn't it generate chi square tests per every level of the by variable? I'd need just one chisq per outcome*risk factor combination.
Try
proc freq data=myData ; table <list of outcome variables * <list of risk variables>j/chisq; run;
When you use a tables statement like
Tables (a b c) * (x y z) you get results for all of the pairs: a*x a*y a*z b*x b*y b*z c*x c*y c*z.
Depends on your data structure. I'm assuming you have a structure something like the following:
riskfactor outcome result
1 1 8
1 1 4
....
Restructuring your data is also pretty straightforward to get this which then helps facilitate a lot of further analysis quite easily.
Tidy data rules should be followed, in general, it saves you time overall.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.