Hello,
I am new to for loops and macro and I can't figure for the life of me how to write a macro so that I can use the proc surveyfreq procedure with chi-square option to assess the associations between all my independent variables (i have 13 so it would take forever to do 1 by 1) so for example this is how i would write for 1 pair of variables, how do i do it to test for all possible pairs?
PROC Surveyfreq data = mydata;
Weight = weight;
Repweight = W1-W1000
TABLE VariableA * Variable1 / chisq;
RUN;
I would really appreciate any help,
Thanks!
You can run multiple table statements and groups.
Dummy code as obviously I don't know your variable names:
PROC Surveyfreq data = mydata; Weight = weight; Repweight = W1-W1000 TABLE Var1 * (Var2 Var3 Var4 <continue obvious pattern until> var13 )/ chisq; TABLE Var2 * (Var3 Var4 <continue obvious pattern until> var13 )/ chisq; TABLE Var3 * (Var4 <continue obvious pattern until> var13 )/ chisq; <same pattern> table var12*var13/ chisq; RUN;
The first table statement pairs var1 with all of the other 12 variables. The second does the second variable with the other 11 variables (var1 and var2 were in the previous statement). Wash, rinse, repeat.
If your variables were actually named with sequential suffixes you could use the list (Var2 - Var13).
IF your variables are adjacent columns in the data set you can use the list with two dashes (Thisvar -- lastvar) in a group.
The gyrations of reducing the variables in each list and multiple tables statements are required because the tables statement will not allow having the same variable appear twice on the same tables statement.
Once you get the first Tables statement written then the editor copy-paste and moving should be easy enough.
Or delve into macro coding.
May I ask ... once you have all these associations between pairs of variables, then what? What use will you be making of them?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.