- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content