Output Data Set of Frequencies
data Color;
input Region Eyes $ Hair $ Count @@;
label Eyes ='Eye Color'
Hair ='Hair Color'
Region='Geographic Region';
datalines;
1 blue fair 23 1 blue red 7 1 blue medium 24
1 blue dark 11 1 green fair 19 1 green red 7
1 green medium 18 1 green dark 14 1 brown fair 34
1 brown red 5 1 brown medium 41 1 brown dark 40
1 brown black 3 2 blue fair 46 2 blue red 21
2 blue medium 44 2 blue dark 40 2 blue black 6
2 green fair 50 2 green red 31 2 green medium 37
2 green dark 23 2 brown fair 56 2 brown red 42
2 brown medium 53 2 brown dark 54 2 brown black 13
;
run;
proc freq data=Color;
tables Eyes Hair Eyes*Hair / out=FreqCount outexpect sparse;
weight Count;
title 'Eye and Hair Color of European Children';
run;
proc print data=FreqCount noobs;
title2 'Output Data Set from PROC FREQ';
run;
/***********************Frequency Dot Plots*************************/
ods graphics on;
proc freq data=Color order=freq;
tables Hair Eyes*Hair / plots=freqplot(type=dot);
tables Region*Hair / plots=freqplot(type=dot scale=percent);
weight Count;
title "***********************Frequency Dot Plots*************************";
title2 'Eye and Hair Color of European Children';
run;
ods graphics off;
/***********************Chi-Square Goodness-of-Fit Tests************************/
proc sort data=Color;
by Region;
run;
ods graphics on;
proc freq data=Color order=data;
tables Hair / nocum chisq testp=(30 12 30 25 3)
plots(only)=deviationplot(type=dot);
weight Count;
by Region;
title "***********************Chi-Square Goodness-of-Fit Tests************************";
title2 'Hair Color of European Children';
run;
ods graphics off;
/************************Binomial Proportions************************/
proc freq data=Color order=freq;
tables Eyes / binomial(ac wilson exact) alpha=.1;
tables Hair / binomial(equiv p=.28 margin=.1);
weight Count;
title "************************Binomial Proportions************************";
title2 'Hair and Eye Color of European Children';
run;
/************************Analysis of a 2x2 Contingency Table*************************/
proc format;
value ExpFmt 1='High Cholesterol Diet'
0='Low Cholesterol Diet';
value RspFmt 1='Yes'
0='No';
run;
data FatComp;
input Exposure Response Count;
label Response='Heart Disease';
datalines;
0 0 6
0 1 2
1 0 4
1 1 11
;
proc sort data=FatComp;
by descending Exposure descending Response;
run;
proc freq data=FatComp order=data;
format Exposure ExpFmt. Response RspFmt.;
tables Exposure*Response / chisq relrisk;
exact pchi or;
weight Count;
title "************************Analysis of a 2x2 Contingency Table*************************";
title2 'Case-Control Study of High Fat/Cholesterol Diet';
run;
/*************************Output Data Set of Chi-Square Statistics*************************/
proc freq data=Color order=data;
tables Eyes*Hair / expected cellchi2 norow nocol chisq;
output out=ChiSqData n nmiss pchi lrchi;
weight Count;
title "*************************Output Data Set of Chi-Square Statistics*************************";
title2 'Chi-Square Tests for 3 by 5 Table of Eye and Hair Color';
run;
proc print data=ChiSqData noobs;
title1 'Chi-Square Statistics for Eye and Hair Color';
title2 'Output Data Set from the FREQ Procedure';
run;
|
222
|
29.13
|
222
|
29.13
|
|
341
|
44.75
|
563
|
73.88
|
|
199
|
26.12
|
762
|
100.00
|
|
22
|
2.89
|
22
|
2.89
|
|
182
|
23.88
|
204
|
26.77
|
|
228
|
29.92
|
432
|
56.69
|
|
217
|
28.48
|
649
|
85.17
|
|
113
|
14.83
|
762
|
100.00
|
|
blue
|
black
|
6
|
6.409
|
0.7874
|
|
blue
|
dark
|
51
|
53.024
|
6.6929
|
|
blue
|
fair
|
69
|
66.425
|
9.0551
|
|
blue
|
medium
|
68
|
63.220
|
8.9239
|
|
blue
|
red
|
28
|
32.921
|
3.6745
|
|
brown
|
black
|
16
|
9.845
|
2.0997
|
|
brown
|
dark
|
94
|
81.446
|
12.3360
|
|
brown
|
fair
|
90
|
102.031
|
11.8110
|
|
brown
|
medium
|
94
|
97.109
|
12.3360
|
|
brown
|
red
|
47
|
50.568
|
6.1680
|
|
green
|
black
|
0
|
5.745
|
0.0000
|
|
green
|
dark
|
37
|
47.530
|
4.8556
|
|
green
|
fair
|
69
|
59.543
|
9.0551
|
|
green
|
medium
|
55
|
56.671
|
7.2178
|
|
green
|
red
|
38
|
29.510
|
4.9869
|
|
228
|
29.92
|
228
|
29.92
|
|
217
|
28.48
|
445
|
58.40
|
|
182
|
23.88
|
627
|
82.28
|
|
113
|
14.83
|
740
|
97.11
|
|
22
|
2.89
|
762
|
100.00
|
Geographic Region=1
|
76
|
30.89
|
30.00
|
|
19
|
7.72
|
12.00
|
|
83
|
33.74
|
30.00
|
|
65
|
26.42
|
25.00
|
|
3
|
1.22
|
3.00
|
Geographic Region=2
|
152
|
29.46
|
30.00
|
|
94
|
18.22
|
12.00
|
|
134
|
25.97
|
30.00
|
|
117
|
22.67
|
25.00
|
|
19
|
3.68
|
3.00
|
|
341
|
44.75
|
341
|
44.75
|
|
222
|
29.13
|
563
|
73.88
|
|
199
|
26.12
|
762
|
100.00
|
|
0.4181
|
0.4773
|
|
0.4174
|
0.4779
|
|
0.4181
|
0.4773
|
|
0.0181
|
|
-2.8981
|
|
0.0019
|
|
0.0038
|
|
228
|
29.92
|
228
|
29.92
|
|
217
|
28.48
|
445
|
58.40
|
|
182
|
23.88
|
627
|
82.28
|
|
113
|
14.83
|
740
|
97.11
|
|
22
|
2.89
|
762
|
100.00
|
|
0.2992
|
|
0.0166
|
|
0.2667
|
|
0.3317
|
|
|
|
|
|
0.2669
|
|
0.3331
|
|
0.0163
|
|
1.1812
|
|
0.1188
|
|
0.2375
|
|
7.1865
|
<.0001
|
|
-4.8701
|
<.0001
|
|
|
<.0001
|
|
0.1800
|
0.3800
|
0.2719
|
0.3265
|
|
Statistics for Table of Exposure by Response
|
|
1
|
4.9597
|
0.0259
|
|
1
|
5.0975
|
0.0240
|
|
1
|
3.1879
|
0.0742
|
|
1
|
4.7441
|
0.0294
|
|
|
0.4644
|
|
|
|
0.4212
|
|
|
|
0.4644
|
|
|
11
|
|
0.9967
|
|
0.0367
|
|
|
|
0.0334
|
|
0.0393
|
|
8.2500
|
1.1535
|
59.0029
|
|
2.9333
|
0.8502
|
10.1204
|
|
0.3556
|
0.1403
|
0.9009
|
|
8.2500
|
|
|
|
|
|
1.1535
|
|
59.0029
|
|
|
|
|
|
0.8677
|
|
105.5488
|
|
Statistics for Table of Eyes by Hair
|
|
8
|
20.9248
|
0.0073
|
|
8
|
25.9733
|
0.0011
|
|
1
|
3.7838
|
0.0518
|
|
|
0.1657
|
|
|
|
0.1635
|
|
|
|
0.1172
|
|
|
762
|
0
|
20.9248
|
8
|
.007349898
|
25.9733
|
8
|
.001061424
|
Cochran-Mantel-Haenszel Statistics
data Migraine;
input Gender $ Treatment $ Response $ Count @@;
datalines;
female Active Better 16 female Active Same 11
female Placebo Better 5 female Placebo Same 20
male Active Better 12 male Active Same 16
male Placebo Better 7 male Placebo Same 19
;
run;
proc freq data=Migraine;
tables Gender*Treatment*Response / cmh;
weight Count;
title 'Clinical Trial for Treatment of Migraine Headaches';
ods graphics off;
run;
Summary Statistics for Treatment by Response Controlling for Gender
|
|
1
|
8.3052
|
0.0040
|
|
1
|
8.3052
|
0.0040
|
|
1
|
8.3052
|
0.0040
|
|
Mantel-Haenszel
|
3.3132
|
1.4456
|
7.5934
|
|
Logit
|
3.2941
|
1.4182
|
7.6515
|
|
Mantel-Haenszel
|
2.1636
|
1.2336
|
3.7948
|
|
Logit
|
2.1059
|
1.1951
|
3.7108
|
|
Mantel-Haenszel
|
0.6420
|
0.4705
|
0.8761
|
|
Logit
|
0.6613
|
0.4852
|
0.9013
|
Cochran-Armitage Trend Test
data pain;
input Dose Adverse $ Count @@;
datalines;
0 No 26 0 Yes 6
1 No 26 1 Yes 7
2 No 23 2 Yes 9
3 No 18 3 Yes 14
4 No 9 4 Yes 23
;
run;
ods graphics on;
proc freq data=Pain;
tables Adverse*Dose / trend measures cl
plots=freqplot(twoway=stacked);
test smdrc;
exact trend / maxtime=60;
weight Count;
title 'Clinical Trial for Treatment of Pain';
run;
ods graphics off;
|
Statistics for Table of Adverse by Dose
|
|
0.5313
|
0.0935
|
0.3480
|
0.7146
|
|
0.3373
|
0.0642
|
0.2114
|
0.4631
|
|
0.4111
|
0.0798
|
0.2547
|
0.5675
|
|
0.4427
|
0.0837
|
0.2786
|
0.6068
|
|
0.2569
|
0.0499
|
0.1592
|
0.3547
|
|
0.3776
|
0.0714
|
0.2378
|
0.5175
|
|
0.3771
|
0.0718
|
0.2363
|
0.5178
|
|
0.1250
|
0.0662
|
0.0000
|
0.2547
|
|
0.2373
|
0.0837
|
0.0732
|
0.4014
|
|
0.1604
|
0.0621
|
0.0388
|
0.2821
|
|
0.0515
|
0.0191
|
0.0140
|
0.0890
|
|
0.1261
|
0.0467
|
0.0346
|
0.2175
|
|
0.0731
|
0.0271
|
0.0199
|
0.1262
|
|
0.2569
|
|
0.0499
|
|
0.1592
|
|
0.3547
|
|
0.0499
|
|
5.1511
|
|
<.0001
|
|
<.0001
|
|
-4.7918
|
|
|
|
|
|
<.0001
|
|
<.0001
|
|
|
|
|
|
<.0001
|
|
<.0001
|
Friedman Chi-Square Test
data Hypnosis;
length Emotion $ 10;
input Subject Emotion $ SkinResponse @@;
datalines;
1 fear 23.1 1 joy 22.7 1 sadness 22.5 1 calmness 22.6
2 fear 57.6 2 joy 53.2 2 sadness 53.7 2 calmness 53.1
3 fear 10.5 3 joy 9.7 3 sadness 10.8 3 calmness 8.3
4 fear 23.6 4 joy 19.6 4 sadness 21.1 4 calmness 21.6
5 fear 11.9 5 joy 13.8 5 sadness 13.7 5 calmness 13.3
6 fear 54.6 6 joy 47.1 6 sadness 39.2 6 calmness 37.0
7 fear 21.0 7 joy 13.6 7 sadness 13.7 7 calmness 14.8
8 fear 20.3 8 joy 23.6 8 sadness 16.3 8 calmness 14.8
;
run;
proc freq data=Hypnosis;
tables Subject*Emotion*SkinResponse /
cmh2 scores=rank noprint;
run;
proc freq data=Hypnosis;
tables Emotion*SkinResponse /
cmh2 scores=rank noprint;
run;
Summary Statistics for Emotion by SkinResponse Controlling for Subject
|
|
1
|
0.2400
|
0.6242
|
|
3
|
6.4500
|
0.0917
|
|
Summary Statistics for Emotion by SkinResponse
|
|
1
|
0.0001
|
0.9933
|
|
3
|
0.5678
|
0.9038
|
Cochran Q Test
proc format;
value $ResponseFmt 'F'='Favorable'
'U'='Unfavorable';
run;
data drugs;
input Drug_A $ Drug_B $ Drug_C $ Count @@;
datalines;
F F F 6 U F F 2
F F U 16 U F U 4
F U F 2 U U F 6
F U U 4 U U U 6
;
run;
proc freq data=Drugs;
tables Drug_A Drug_B Drug_C / nocum;
tables Drug_A*Drug_B*Drug_C / agree noprint;
format Drug_A Drug_B Drug_C $ResponseFmt.;
weight Count;
title 'Study of Three Drug Treatments for a Chronic Disease';
run;
Statistics for Table 1 of Drug_B by Drug_C Controlling for Drug_A=Favorable
|
|
-0.0328
|
|
0.1167
|
|
-0.2615
|
|
0.1960
|
Statistics for Table 2 of Drug_B by Drug_C Controlling for Drug_A=Unfavorable
|
|
-0.1538
|
|
0.2230
|
|
-0.5909
|
|
0.2832
|
Summary Statistics for Drug_B by Drug_C Controlling for Drug_A
|
|
-0.0588
|
|
0.1034
|
|
-0.2615
|
|
0.1439
|