BookmarkSubscribeRSS Feed
skycuddle
Calcite | Level 5

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!

 

2 REPLIES 2
ballardw
Super User

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.

PaigeMiller
Diamond | Level 26

May I ask ... once you have all these associations between pairs of variables, then what? What use will you be making of them?

--
Paige Miller

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 613 views
  • 0 likes
  • 3 in conversation