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

Hi,

 

Please help me with SAS code for 3 ways contingency table. I want my table to look like below. Any help would be appreciated.

Image result for 3-way contingency table

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

For future reference: When pasting a log file, or an output from a procedure, click on the {i} icon and paste your text into that window.

 

Try something like this:

 

proc report data=have;
    columns x1 x2 x3;
    define x1/group "Label for X1";
    define x2/group "Label for X2";
    define x3/across "Label for X3";
run;
--
Paige Miller

View solution in original post

9 REPLIES 9
PaigeMiller
Diamond | Level 26

The basic form of the analysis is:

 

proc freq data=have;
    tables x1*x2*x3;
run;

PROC FREQ has lots of options: https://documentation.sas.com/?cdcId=pgmmvacdc&cdcVersion=9.4&docsetId=statug&docsetTarget=statug_fr...

 

Also, PROC REPORT ought to be able to do this.

--
Paige Miller
Kyra
Quartz | Level 8
Thanks for the reply.

proc freq data=red.shruti1;
tables pillsprescribed1*Satisfaction*GENDER;run;

It is giving me something like below. I want all the three variables in
same table. satisfaction, gender, pills prescribed.

SAS Output
The FREQ Procedure

Frequency
Percent
Row Pct
Col Pct
Table 1 of Satisfaction by GENDER
Controlling for pillsprescribed1=1
Satisfaction(Satisfaction) GENDER(GENDER)
0 1 Total
Dissatisfied
0
0.00
.
0.00
0
0.00
.
0.00
0
0.00


Highly Dissatisfied
0
0.00
0.00
0.00
1
25.00
100.00
33.33
1
25.00


Highly Satisfied
0
0.00
0.00
0.00
2
50.00
100.00
66.67
2
50.00


Satisfied
1
25.00
100.00
100.00
0
0.00
0.00
0.00
1
25.00


Total
1
25.00
3
75.00
4
100.00

Frequency
Percent
Row Pct
Col Pct
Table 2 of Satisfaction by GENDER
Controlling for pillsprescribed1=2
Satisfaction(Satisfaction) GENDER(GENDER)
0 1 Total
Dissatisfied
0
0.00
0.00
0.00
3
8.57
100.00
17.65
3
8.57


Highly Dissatisfied
1
2.86
100.00
5.56
0
0.00
0.00
0.00
1
2.86


Highly Satisfied
7
20.00
50.00
38.89
7
20.00
50.00
41.18
14
40.00


Satisfied
10
28.57
58.82
55.56
7
20.00
41.18
41.18
17
48.57


Total
18
51.43
17
48.57
35
100.00
Frequency Missing = 2

Frequency
Percent
Row Pct
Col Pct
Table 3 of Satisfaction by GENDER
Controlling for pillsprescribed1=3
Satisfaction(Satisfaction) GENDER(GENDER)
0 1 Total
Dissatisfied
2
4.17
40.00
6.67
3
6.25
60.00
16.67
5
10.42


Highly Dissatisfied
2
4.17
100.00
6.67
0
0.00
0.00
0.00
2
4.17


Highly Satisfied
9
18.75
50.00
30.00
9
18.75
50.00
50.00
18
37.50


Satisfied
17
35.42
73.91
56.67
6
12.50
26.09
33.33
23
47.92


Total
30
62.50
18
37.50
48
100.00
Frequency Missing = 1

PaigeMiller
Diamond | Level 26

For future reference: When pasting a log file, or an output from a procedure, click on the {i} icon and paste your text into that window.

 

Try something like this:

 

proc report data=have;
    columns x1 x2 x3;
    define x1/group "Label for X1";
    define x2/group "Label for X2";
    define x3/across "Label for X3";
run;
--
Paige Miller
Reeza
Super User

You want PROC TABULATE then instead:

 

proc tabulate data=have;
class def_race victim_race death_penalty;
table def_race="Defandant's Race"*victim_race="Victim's Race" , death_penalty="Death Penalty";
run; 

@Kyra wrote:

Hi,

 

Please help me with SAS code for 3 ways contingency table. I want my table to look like below. Any help would be appreciated.

Image result for 3-way contingency table


 

Kyra
Quartz | Level 8

Thank you very much. This code also worked.

one further question-

 

Is it possible to do chisq/fisher's for these kind of 3 way contingency tables.

 

Thanks,

 

 

Reeza
Super User
Yes, but not via PROC TABULATE, I think you need PROC FREQ for that.
Kyra
Quartz | Level 8
oh, okay. Thanks.
Reeza
Super User

Actually....it can't it does two way tables. Not sure what you would do for a three way table, maybe catmod or proc logistic I suspect.

Kyra
Quartz | Level 8
Hi, I think Log-linear model is the anwer. Proc Genmod

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 9 replies
  • 6876 views
  • 4 likes
  • 3 in conversation