Quartz | Level 8

## frequency table when you have many variables

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
Super User

## Re: frequency table when you have many variables

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

Super User

## Re: frequency table when you have many variables

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

Discussion stats