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

I am trying to write code in SAS to do a 3-way cross tabulation. For example, if I have 3 categorical variables and I want to look at gender and incident by schooltype.

I wrote code as follows:

proc freq data = mydata;

tables gender*incident*schooltype / chisq;

run;

However, the output only shows a 2x2 table and gender was controlled for.

Can you help me figure out the correct code? Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

I'm still not sure what you are trying to do.  Is is something like the following?:

data test;

  set sashelp.class;

  if height gt 62 then height=1;

  else height=0;

  if weight gt 99 then weight=1;

  else weight=0;

run;

proc sort data=test;

  by sex;

run;

proc freq data=test ;

  tables height*weight/ chisq measures cmh;

  by sex;

run;

View solution in original post

4 REPLIES 4
art297
Opal | Level 21

That is the way SAS outputs a 3 or more way crosstabulation.  If you wanted to achieve a different output you would have to design your own using something like proc report or proc tabulate.

kvc
Calcite | Level 5 kvc
Calcite | Level 5

I looked at proc tabulate and it's hard to figure out. I'm trying to understand which variable is designated as the control variable - is it the meta variable, i.e., schooltype? Here's some code I found:

proc freq data=kali.chks4 order=formatted ;

     tables schooltype*(gender incident)/ noprint chisq measures cmh;

run;

I simply want to see what gender*incident looks like by school type.

art297
Opal | Level 21

I'm still not sure what you are trying to do.  Is is something like the following?:

data test;

  set sashelp.class;

  if height gt 62 then height=1;

  else height=0;

  if weight gt 99 then weight=1;

  else weight=0;

run;

proc sort data=test;

  by sex;

run;

proc freq data=test ;

  tables height*weight/ chisq measures cmh;

  by sex;

run;

kvc
Calcite | Level 5 kvc
Calcite | Level 5

This is what I needed. I needed to run the cross tab by the school type. The output is kind of strange though. It gave me four tables, not two, with two tables containing output for one school type, and two tables containing output for another  school type. I wonder if my dataset is too large for one table? In any event, the code you gave me was great, so thank you very much.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 4 replies
  • 6979 views
  • 0 likes
  • 2 in conversation