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

Dear all,

I would like to able to produce a cross table with 8 independent categorical variables the same way PROC CORR tabulates the correlation coefficients. I would need to know the frequency of each variable in relation to the other independent variable. I have tried PROC FREQ with the table feature which does part of what I would like but I would love to combine all that information into 1 table.

 

Thank you,

Pieter

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@paldejong wrote:

Dear all,

I would like to able to produce a cross table with 8 independent categorical variables the same way PROC CORR tabulates the correlation coefficients. I would need to know the frequency of each variable in relation to the other independent variable. I have tried PROC FREQ with the table feature which does part of what I would like but I would love to combine all that information into 1 table.

 

Thank you,

Pieter


"Each variable" or "each value of each variable"?

 

I don't know if this gives you a start or not but is at least quick and easy to test.

proc tabulate data=sashelp.class;
   class sex age;
   tables sex age,
          sex age
          /misstext=' '
    ;
run;

Any variable you place on the Class statement in tabulate will be treated as "categorical". The table statement places each variable in both a row and column. The misstext suppresses the many . you will get for missing values when any variable crosses with itself. There will be a warning in the log for each variable crossed with itself. No statistic is requested so you will N, or count.

Caution: Tabulate will by default remove records with any missing values for any class variables. If you don't want that then you would add the option \missing to the Class statement, which will then treat missing as a level of the variable.

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

It doesn't make sense to say you want a table involving categorical variables similar to PROC CORR, because PROC CORR works on continuous variables. The is no such table of categorical variables analogous to what PROC CORR produces.

 

So, you need to refine or re-think your question.

 

Better yet, show us an example with (let's say) three categorical variables, show us what you want.

--
Paige Miller
ballardw
Super User

@paldejong wrote:

Dear all,

I would like to able to produce a cross table with 8 independent categorical variables the same way PROC CORR tabulates the correlation coefficients. I would need to know the frequency of each variable in relation to the other independent variable. I have tried PROC FREQ with the table feature which does part of what I would like but I would love to combine all that information into 1 table.

 

Thank you,

Pieter


"Each variable" or "each value of each variable"?

 

I don't know if this gives you a start or not but is at least quick and easy to test.

proc tabulate data=sashelp.class;
   class sex age;
   tables sex age,
          sex age
          /misstext=' '
    ;
run;

Any variable you place on the Class statement in tabulate will be treated as "categorical". The table statement places each variable in both a row and column. The misstext suppresses the many . you will get for missing values when any variable crosses with itself. There will be a warning in the log for each variable crossed with itself. No statistic is requested so you will N, or count.

Caution: Tabulate will by default remove records with any missing values for any class variables. If you don't want that then you would add the option \missing to the Class statement, which will then treat missing as a level of the variable.

paldejong
Fluorite | Level 6
That is exactly what I needed.
Thank you!
Pieter

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 3 replies
  • 742 views
  • 1 like
  • 3 in conversation