BookmarkSubscribeRSS Feed
_maldini_
Barite | Level 11

I want to create multiple 2-way tables to assess bivariate associations between categorical variables. Basically, I want all possible 2-way combinations of the variables. 

I'm using a macro variable to represent the list of variables: 

%let cat_vars = 
	sex
	race_all
	edu
	hh_income
	etoh_days_per_wk
	smk_status
	lipid_meds 
	diab_meds 
	;

Is there syntax that will spare me from having to type out all possible combinations of these variables?

 

Thanks.

2 REPLIES 2
ballardw
Super User

Since you didn't show any actual Proc freq or surveyfreq code the answer is "maybe".

You can use ( ) to indicate a group of variables to compare with others in a table statement:

  (a b c) * (d e) for example will do tables a*d b*d c*d a*e b*e c*e.

So if you have a group of demographic variables such as sex, age group, race, ethnicity that you want to compare with responses like income those are easy. Have the demographics in one set of parentheses and the other responses in a different group.

Or if you really want all with all , where you will get sex*sex as a result

 

Tables (&cat_vars.) * (&cat_vars);

 

For the truly lazy that want to generate horrific amounts of output perhaps: tables _all_ * _all_ ;

The tables statements in Freq and Surveyfreq will accept the list words _all_ (every single variable), _numeric_ (all the numeric variables) and/or _character_ all of the character variables.

_maldini_
Barite | Level 11

 

proc surveyfreq data=work.data_2009_2018;
 	stratum sdmvstra;
 	cluster sdmvpsu;
 	weight wtmec10yr_09_18;
 	tables 	(&cat_vars)*(&cat_vars) / chisq;
run;

<Or if you really want all with all, where you will get sex*sex as a result>

 

Yes, I do, even though I would just disregard sex*sex, race*race and other 2-way tables involving the same variable.

 

When I use the syntax above, I get an error in the log: 

Screenshot 2023-03-13 at 12.44.15 PM.png

Thanks for your help.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 794 views
  • 1 like
  • 2 in conversation