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

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.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

 

 

View solution in original post

4 REPLIES 4
Reeza
Super User
Don't think you need macros. I think you need one to be a BY statement instead.

It'll depend a bit on your table structure, which you may need to change but you don't need macros for this.
antonsvart
Fluorite | Level 6

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.

ballardw
Super User

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.

 

 

Reeza
Super User

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. 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1038 views
  • 2 likes
  • 3 in conversation