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

Hello all,

Appreciate you helping me find a way to get two by two frequency table apply proc freq. I have many categorical variables, it is time consuming to enter all variables two by two.

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@fatemeh wrote:

Hello all,

Appreciate you helping me find a way to get two by two frequency table apply proc freq. I have many categorical variables, it is time consuming to enter all variables two by two.

 


The proc freq tables statement allows use of parentheses to create "groups" of variables that get treated similarly.

So

tables (a b c d) *(p d q r); is short hand for all of the pairs of the variables in the first parentheses and all in the second:

a*p a*d a*q a*r b*p b*c b*q b*r etc.

You cal also use variable lists:

tables (a1-a10 ) *(v1-v15). If you have 10 variables that start with a. So that would do a1*v1 a1*v2 ... a1*v15 a2*v1 ... a2*v15 ... a10*v1 .. a10*v15.

 

you could cross all of the variables using the special list _all_.

 

Tables _all_* _all_;

but don't expect to get the output quickly with a large data set with lots of variables. 50 variables in the data set means 50*50 tables, or 2500.

 

 

View solution in original post

1 REPLY 1
ballardw
Super User

@fatemeh wrote:

Hello all,

Appreciate you helping me find a way to get two by two frequency table apply proc freq. I have many categorical variables, it is time consuming to enter all variables two by two.

 


The proc freq tables statement allows use of parentheses to create "groups" of variables that get treated similarly.

So

tables (a b c d) *(p d q r); is short hand for all of the pairs of the variables in the first parentheses and all in the second:

a*p a*d a*q a*r b*p b*c b*q b*r etc.

You cal also use variable lists:

tables (a1-a10 ) *(v1-v15). If you have 10 variables that start with a. So that would do a1*v1 a1*v2 ... a1*v15 a2*v1 ... a2*v15 ... a10*v1 .. a10*v15.

 

you could cross all of the variables using the special list _all_.

 

Tables _all_* _all_;

but don't expect to get the output quickly with a large data set with lots of variables. 50 variables in the data set means 50*50 tables, or 2500.

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 449 views
  • 1 like
  • 2 in conversation