# Categorical Data Analysis: Chapter 10

```

options nodate nonumber ps=200 ls=80 formdlim=' ';

data trial;
drop center1 i_sex1 age1 initial1 improve1 trtsex1 trtinit1
trtage1 isexage1 isexint1 iageint1;
retain center1 i_sex1 age1 initial1 improve1 trtsex1 trtinit1
trtage1 isexage1 isexint1 iageint1 0;
input center treat \$ sex \$ age improve initial @@;
/* compute model terms for each observation */
i_sex=(sex='m');       i_trt=(treat='t');
trtsex=i_sex*i_trt;    trtinit=i_trt*initial;
trtage=i_trt*age;      isexage=i_sex*age;
isexinit=i_sex*initial;iageinit=age*initial;
/* compute differences for paired observation */
if (center=center1) then do;
pair=10*improve + improve1;
i_sex=i_sex1-i_sex;
age=age1-age;
initial=initial1-initial;
trtsex=trtsex1-trtsex;
trtinit=trtinit1-trtinit;
trtage=trtage1-trtage;
isexage=isexage1-isexage;
isexint=isexint1-isexinit;
iageinit=iageint1-iageinit;
if (pair=10 or pair=1) then do;
/* output discordant pair observations */
improve=(pair=1); output trial; end;
end;
else do;
center1=center; age1=age;
initial1=initial; i_sex1=i_sex; improve1=improve;
trtsex1=trtsex; trtinit1=trtinit; trtage1=trtage;
isexage1=isexage; isexint1=isexinit; iageint1=iageinit;
end;
datalines;
1  t f 27 0 1  1 p f 32 0 2 41 t f 13 1 2 41 p m 22 0 3
2  t f 41 1 3  2 p f 47 0 1 42 t m 31 1 1 42 p f 21 1 3
3  t m 19 1 4  3 p m 31 0 4 43 t f 19 1 3 43 p m 35 1 3
4  t m 55 1 1  4 p m 24 1 3 44 t m 31 1 3 44 p f 37 0 2
5  t f 51 1 4  5 p f 44 0 2 45 t f 44 0 1 45 p f 41 1 1
6  t m 23 0 1  6 p f 44 1 3 46 t m 41 1 2 46 p m 41 0 1
7  t m 31 1 2  7 p f 39 0 2 47 t m 41 1 2 47 p f 21 0 4
8  t m 22 0 1  8 p m 54 1 4 48 t f 51 1 2 48 p m 22 1 1
9  t m 37 1 3  9 p m 63 0 2 49 t f 62 1 3 49 p f 32 0 3
10 t m 33 0 3 10 p f 43 0 3 50 t m 21 0 1 50 p m 34 0 1
11 t f 32 1 1 11 p m 33 0 3 51 t m 55 1 3 51 p f 35 1 2
12 t m 47 1 4 12 p m 24 0 4 52 t f 61 0 1 52 p m 19 0 1
13 t m 55 1 3 13 p f 38 1 1 53 t m 43 1 2 53 p m 31 0 2
14 t f 33 0 1 14 p f 28 1 2 54 t f 44 1 1 54 p f 41 1 1
15 t f 48 1 1 15 p f 42 0 1 55 t m 67 1 2 55 p m 41 0 1
16 t m 55 1 3 16 p m 52 0 1 56 t m 41 0 2 56 p m 21 1 4
17 t m 30 0 4 17 p m 48 1 4 57 t f 51 1 3 57 p m 51 0 2
18 t f 31 1 2 18 p m 27 1 3 58 t m 62 1 3 58 p m 54 1 3
19 t m 66 1 3 19 p f 54 0 1 59 t m 22 0 1 59 p f 22 0 1
20 t f 45 0 2 20 p f 66 1 2 60 t m 42 1 2 60 p f 29 1 2
21 t m 19 1 4 21 p f 20 1 4 61 t f 51 1 1 61 p f 31 0 1
22 t m 34 1 4 22 p f 31 0 1 62 t m 27 0 2 62 p m 32 1 2
23 t f 46 0 1 23 p m 30 1 2 63 t m 31 1 1 63 p f 21 0 1
24 t m 48 1 3 24 p f 62 0 4 64 t m 35 0 3 64 p m 33 1 3
25 t m 50 1 4 25 p m 45 1 4 65 t m 67 1 2 65 p m 19 0 1
26 t m 57 1 3 26 p f 43 0 3 66 t m 41 0 2 66 p m 62 1 4
27 t f 13 0 2 27 p m 22 1 3 67 t f 31 1 2 67 p m 45 1 3
28 t m 31 1 1 28 p f 21 0 1 68 t m 34 1 1 68 p f 54 0 1
29 t m 35 1 3 29 p m 35 1 3 69 t f 21 0 1 69 p m 34 1 4
30 t f 36 1 3 30 p f 37 0 3 70 t m 64 1 3 70 p m 51 0 1
31 t f 45 0 1 31 p f 41 1 1 71 t f 61 1 3 71 p m 34 1 3
32 t m 13 1 2 32 p m 42 0 1 72 t m 33 0 1 72 p f 43 0 1
33 t m 14 0 4 33 p f 22 1 2 73 t f 36 0 2 73 p m 37 0 3
34 t f 15 1 2 34 p m 24 0 1 74 t m 21 1 1 74 p m 55 0 1
35 t f 19 1 3 35 p f 31 0 1 75 t f 47 0 2 75 p f 42 1 3
36 t m 20 0 2 36 p m 32 1 3 76 t f 51 1 4 76 p m 44 0 2
37 t m 23 1 3 37 p f 35 0 1 77 t f 23 1 1 77 p m 41 1 3
38 t f 23 0 1 38 p m 21 1 1 78 t m 31 0 2 78 p f 23 1 4
39 t m 24 1 4 39 p m 30 1 3 79 t m 22 0 1 79 p m 19 1 4
40 t m 57 1 3 40 p f 43 1 3
;

proc logistic data=trial descending;
model improve = initial age i_sex
isexage isexinit iageinit
trtsex trtinit trtage /
selection=forward include=3 details;
run;

proc logistic data=trial descending;
model improve = ;
run;

data trial2;
input center treat \$ sex \$ age improve initial @@;
/* create indicator variables for sex and interaction terms */
improve=2-improve;
isex=(sex='m');
itreat=(treat='t');
sex_age=isex*age;
treat_age=itreat*age;
sex_treat=isex*itreat;
sex_initial=isex*initial;
treat_initial=itreat*initial;
age_initial=age*initial;
datalines;
1  t f 27 0 1  1 p f 32 0 2 41 t f 13 1 2 41 p m 22 0 3
2  t f 41 1 3  2 p f 47 0 1 42 t m 31 1 1 42 p f 21 1 3
3  t m 19 1 4  3 p m 31 0 4 43 t f 19 1 3 43 p m 35 1 3
4  t m 55 1 1  4 p m 24 1 3 44 t m 31 1 3 44 p f 37 0 2
5  t f 51 1 4  5 p f 44 0 2 45 t f 44 0 1 45 p f 41 1 1
6  t m 23 0 1  6 p f 44 1 3 46 t m 41 1 2 46 p m 41 0 1
7  t m 31 1 2  7 p f 39 0 2 47 t m 41 1 2 47 p f 21 0 4
8  t m 22 0 1  8 p m 54 1 4 48 t f 51 1 2 48 p m 22 1 1
9  t m 37 1 3  9 p m 63 0 2 49 t f 62 1 3 49 p f 32 0 3
10 t m 33 0 3 10 p f 43 0 3 50 t m 21 0 1 50 p m 34 0 1
11 t f 32 1 1 11 p m 33 0 3 51 t m 55 1 3 51 p f 35 1 2
12 t m 47 1 4 12 p m 24 0 4 52 t f 61 0 1 52 p m 19 0 1
13 t m 55 1 3 13 p f 38 1 1 53 t m 43 1 2 53 p m 31 0 2
14 t f 33 0 1 14 p f 28 1 2 54 t f 44 1 1 54 p f 41 1 1
15 t f 48 1 1 15 p f 42 0 1 55 t m 67 1 2 55 p m 41 0 1
16 t m 55 1 3 16 p m 52 0 1 56 t m 41 0 2 56 p m 21 1 4
17 t m 30 0 4 17 p m 48 1 4 57 t f 51 1 3 57 p m 51 0 2
18 t f 31 1 2 18 p m 27 1 3 58 t m 62 1 3 58 p m 54 1 3
19 t m 66 1 3 19 p f 54 0 1 59 t m 22 0 1 59 p f 22 0 1
20 t f 45 0 2 20 p f 66 1 2 60 t m 42 1 2 60 p f 29 1 2
21 t m 19 1 4 21 p f 20 1 4 61 t f 51 1 1 61 p f 31 0 1
22 t m 34 1 4 22 p f 31 0 1 62 t m 27 0 2 62 p m 32 1 2
23 t f 46 0 1 23 p m 30 1 2 63 t m 31 1 1 63 p f 21 0 1
24 t m 48 1 3 24 p f 62 0 4 64 t m 35 0 3 64 p m 33 1 3
25 t m 50 1 4 25 p m 45 1 4 65 t m 67 1 2 65 p m 19 0 1
26 t m 57 1 3 26 p f 43 0 3 66 t m 41 0 2 66 p m 62 1 4
27 t f 13 0 2 27 p m 22 1 3 67 t f 31 1 2 67 p m 45 1 3
28 t m 31 1 1 28 p f 21 0 1 68 t m 34 1 1 68 p f 54 0 1
29 t m 35 1 3 29 p m 35 1 3 69 t f 21 0 1 69 p m 34 1 4
30 t f 36 1 3 30 p f 37 0 3 70 t m 64 1 3 70 p m 51 0 1
31 t f 45 0 1 31 p f 41 1 1 71 t f 61 1 3 71 p m 34 1 3
32 t m 13 1 2 32 p m 42 0 1 72 t m 33 0 1 72 p f 43 0 1
33 t m 14 0 4 33 p f 22 1 2 73 t f 36 0 2 73 p m 37 0 3
34 t f 15 1 2 34 p m 24 0 1 74 t m 21 1 1 74 p m 55 0 1
35 t f 19 1 3 35 p f 31 0 1 75 t f 47 0 2 75 p f 42 1 3
36 t m 20 0 2 36 p m 32 1 3 76 t f 51 1 4 76 p m 44 0 2
37 t m 23 1 3 37 p f 35 0 1 77 t f 23 1 1 77 p m 41 1 3
38 t f 23 0 1 38 p m 21 1 1 78 t m 31 0 2 78 p f 23 1 4
39 t m 24 1 4 39 p m 30 1 3 79 t m 22 0 1 79 p m 19 1 4
40 t m 57 1 3 40 p f 43 1 3
;

proc phreg data=trial2 nosummary;
strata center;
model improve = initial age isex itreat
sex_age sex_initial age_initial
sex_treat treat_initial treat_age / ties=discrete
selection=forward include=4 details;
run;

data cross1 (drop=count);
input age \$ sequence \$ time1 \$ time2 \$ count;
do i=1 to count;
output;
end;
datalines;
older AB F F 12
older AB F U 12
older AB U F 6
older AB U U 20
older BP F F 8
older BP F U 5
older BP U F 6
older BP U U 31
older PA F F 5
older PA F U 3
older PA U F 22
older PA U U 20
younger BA F F 19
younger BA F U 3
younger BA U F  25
younger BA U U  3
younger AP F F 25
younger AP F U 6
younger AP U F 6
younger AP U U 13
younger PB F F 13
younger PB F U 5
younger PB U F 21
younger PB U U 11
;

data cross2; set cross1;
subject=_n_;
period1=1;
druga = (substr(sequence, 1, 1)='A');
drugb = (substr(sequence, 1, 1)='B');
carrya=0;
carryb=0;
response =(time1='F');
output;
period1=0;
druga =  (substr(sequence, 2, 1)='A');
drugb =  (substr(sequence, 2, 1)='B');
carrya = (substr(sequence, 1, 1)='A');
carryb = (substr(sequence, 1, 1)='B');
response =(time2='F');
output;
run;

data cross3;
set cross2;
response=2-response;
older=(age='older');
druga_older=druga*older;
drugb_older=drugb*older;
period1_older=period1*older;
run;

proc phreg data=cross3 nosummary;
strata subject;
model response = period1 druga drugb period1_older
carrya carryb / ties=discrete;
run;

proc phreg data=cross3 nosummary;
strata subject;
model response = period1 druga drugb
period1_older / ties=discrete;
A_B: test druga=drugb;
run;

data exercise;
input Sequence \$ ID \$ Period1 Period2 High Medium Baseline
Response CarryHigh CarryMedium @@;
strata=sequence||id;
DichotResponse = 2-(Response >0);
datalines;
HML 1   1 0 1 0 0 3 0 0 HML 1   0 1 0 1 0 1 1 0 HML 1   0 0 0 0 0 0 0 1
HML 2   1 0 1 0 0 3 0 0 HML 2   0 1 0 1 0 2 1 0 HML 2   0 0 0 0 0 0 0 1
HML 3   1 0 1 0 1 3 0 0 HML 3   0 1 0 1 0 2 1 0 HML 3   0 0 0 0 0 0 0 1
HML 4   1 0 1 0 0 2 0 0 HML 4   0 1 0 1 0 0 1 0 HML 4   0 0 0 0 0 2 0 1
HML 5   1 0 1 0 0 3 0 0 HML 5   0 1 0 1 0 0 1 0 HML 5   0 0 0 0 0 1 0 1
HML 6   1 0 1 0 1 2 0 0 HML 6   0 1 0 1 0 1 1 0 HML 6   0 0 0 0 0 2 0 1
HML 7   1 0 1 0 0 3 0 0 HML 7   0 1 0 1 0 1 1 0 HML 7   0 0 0 0 0 2 0 1
HML 8   1 0 1 0 0 3 0 0 HML 8   0 1 0 1 0 2 1 0 HML 8   0 0 0 0 0 1 0 1
HML 9   1 0 1 0 1 2 0 0 HML 9   0 1 0 1 0 1 1 0 HML 9   0 0 0 0 0 1 0 1
HML 10  1 0 1 0 0 1 0 0 HML 10  0 1 0 1 0 1 1 0 HML 10  0 0 0 0 0 0 0 1
HML 11  1 0 1 0 0 2 0 0 HML 11  0 1 0 1 0 0 1 0 HML 11  0 0 0 0 0 0 0 1
HML 12  1 0 1 0 0 3 0 0 HML 12  0 1 0 1 0 0 1 0 HML 12  0 0 0 0 0 0 0 1
HML 13  1 0 1 0 0 1 0 0 HML 13  0 1 0 1 0 3 1 0 HML 13  0 0 0 0 0 1 0 1
HML 14  1 0 1 0 0 2 0 0 HML 14  0 1 0 1 0 2 1 0 HML 14  0 0 0 0 0 0 0 1
HML 15  1 0 1 0 1 2 0 0 HML 15  0 1 0 1 0 2 1 0 HML 15  0 0 0 0 0 0 0 1
HML 16  1 0 1 0 1 2 0 0 HML 16  0 1 0 1 0 2 1 0 HML 16  0 0 0 0 0 0 0 1
HML 17  1 0 1 0 1 2 0 0 HML 17  0 1 0 1 0 2 1 0 HML 17  0 0 0 0 0 3 0 1
HML 18  1 0 1 0 0 2 0 0 HML 18  0 1 0 1 0 2 1 0 HML 18  0 0 0 0 0 2 0 1
HML 19  1 0 1 0 0 2 0 0 HML 19  0 1 0 1 0 0 1 0 HML 19  0 0 0 0 0 2 0 1
HML 20  1 0 1 0 0 3 0 0 HML 20  0 1 0 1 0 0 1 0 HML 20  0 0 0 0 0 1 0 1
HML 21  1 0 1 0 0 1 0 0 HML 21  0 1 0 1 0 1 1 0 HML 21  0 0 0 0 0 0 0 1
HML 22  1 0 1 0 0 2 0 0 HML 22  0 1 0 1 0 0 1 0 HML 22  0 0 0 0 0 2 0 1
HML 23  1 0 1 0 0 2 0 0 HML 23  0 1 0 1 0 1 1 0 HML 23  0 0 0 0 0 1 0 1
HML 24  1 0 1 0 1 3 0 0 HML 24  0 1 0 1 0 1 1 0 HML 24  0 0 0 0 0 0 0 1
HML 25  1 0 1 0 0 3 0 0 HML 25  0 1 0 1 0 2 1 0 HML 25  0 0 0 0 0 1 0 1
HML 26  1 0 1 0 0 3 0 0 HML 26  0 1 0 1 0 2 1 0 HML 26  0 0 0 0 0 0 0 1
HLM 1   1 0 1 0 0 3 0 0 HLM 1   0 1 0 0 0 0 1 0 HLM 1   0 0 0 1 0 2 0 0
HLM 2   1 0 1 0 0 2 0 0 HLM 2   0 1 0 0 0 1 1 0 HLM 2   0 0 0 1 0 1 0 0
HLM 3   1 0 1 0 1 2 0 0 HLM 3   0 1 0 0 0 2 1 0 HLM 3   0 0 0 1 0 2 0 0
HLM 4   1 0 1 0 0 2 0 0 HLM 4   0 1 0 0 0 2 1 0 HLM 4   0 0 0 1 0 1 0 0
HLM 5   1 0 1 0 0 3 0 0 HLM 5   0 1 0 0 0 1 1 0 HLM 5   0 0 0 1 0 1 0 0
HLM 6   1 0 1 0 1 1 0 0 HL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1
LMH 15  1 0 0 0 1 0 0 0 LMH 15  0 1 0 1 0 1 0 0 LMH 15  0 0 1 0 0 1 0 1
LMH 16  1 0 0 0 1 1 0 0 LMH 16  0 1 0 1 0 2 0 0 LMH 16  0 0 1 0 0 0 0 1
LMH 17  1 0 0 0 1 2 0 0 LMH 17  0 1 0 1 0 1 0 0 LMH 17  0 0 1 0 0 0 0 1
LMH 18  1 0 0 0 0 1 0 0 LMH 18  0 1 0 1 0 0 0 0 LMH 18  0 0 1 0 0 1 0 1
LMH 19  1 0 0 0 0 1 0 0 LMH 19  0 1 0 1 0 2 0 0 LMH 19  0 0 1 0 0 2 0 1
LMH 20  1 0 0 0 0 0 0 0 LMH 20  0 1 0 1 0 2 0 0 LMH 20  0 0 1 0 0 3 0 1
LMH 21  1 0 0 0 0 0 0 0 LMH 21  0 1 0 1 0 1 0 0 LMH 21  0 0 1 0 0 1 0 1
LMH 22  1 0 0 0 0 0 0 0 LMH 22  0 1 0 1 0 2 0 0 LMH 22  0 0 1 0 0 2 0 1
LMH 23  1 0 0 0 0 0 0 0 LMH 23  0 1 0 1 0 1 0 0 LMH 23  0 0 1 0 0 2 0 1
LMH 24  1 0 0 0 1 0 0 0 LMH 24  0 1 0 1 0 2 0 0 LMH 24  0 0 1 0 0 2 0 1
;

proc phreg data=exercise nosummary;
strata strata;
model DichotResponse = period1 period2 high medium baseline
CarryHigh CarryMedium / ties=discrete;
Reduce: test CarryHigh=CarryMedium=period1=period2=0;
run;

ods select ResidualChiSq ParameterEstimates TestStmts;
proc phreg data=exercise nosummary;
strata strata;
model DichotResponse = high medium baseline
/ selection=forward rl include=2 details ties=discrete;
Treat: test high = medium = 0;
run;

data diagnosis;
input std1 \$ test1 \$ std2 \$ test2 \$ count;
do i=1 to count;
output;
end;
datalines;
Neg Neg Neg Neg 509
Neg Neg Neg Pos   4
Neg Neg Pos Neg  17
Neg Neg Pos Pos   3
Neg Pos Neg Neg  13
Neg Pos Neg Pos   8
Neg Pos Pos Neg   0
Neg Pos Pos Pos   8
Pos Neg Neg Neg  14
Pos Neg Neg Pos   1
Pos Neg Pos Neg  17
Pos Neg Pos Pos   9
Pos Pos Neg Neg   7
Pos Pos Neg Pos   4
Pos Pos Pos Neg   9
Pos Pos Pos Pos 170
;
run;

data diagnosis2;
set diagnosis;
drop std1 test1 std2 test2;
subject=_n_;
time=0; procedure=0;
response=std1; output;
time=0; procedure=1;
response=test1; output;
time=1; procedure=0;
response=std2; output;
time=1; procedure=1;
response=test2; output;
run;

data diagnosis3;
set diagnosis2;
outcome = 2 - (response='Neg');
time_procedure=time*procedure;

proc phreg data=diagnosis3 nosummary;
strata subject;
model outcome=time procedure
time_procedure /ties=discrete;
run;

proc phreg data=diagnosis3 nosummary;
strata subject;
model outcome=time procedure time_procedure
/ties=discrete selection=forward include=2 details rl;
run;

data match1;
drop   id1 gall1 hyper1 age1 est1 nonest1 gallest1;
retain id1 gall1 hyper1 age1 est1 nonest1 gallest1 0;
input id case age est gall hyper nonest @@;
gallest=est*gall;
if (id = id1) then do;
gall=gall1-gall; hyper=hyper1-hyper; age=age1-age;
est=est1-est;  nonest=nonest1-nonest;
gallest=gallest1-gallest;
output;
end;
else do;
id1=id; gall1=gall; hyper1=hyper; age1=age;
est1=est; nonest1=nonest; gallest1=gallest;
end;
datalines;
1 1 74 1 0 0  1  1 0 75 0 0 0  0
2 1 67 1 0 0  1  2 0 67 0 0 1  1
3 1 76 1 0 1  1  3 0 76 1 0 1  1
4 1 71 1 0 0  0  4 0 70 1 1 0  1
5 1 69 1 1 0  1  5 0 69 1 0 1  1
6 1 70 1 0 1  1  6 0 71 0 0 0  0
7 1 65 1 1 0  1  7 0 65 0 0 0  0
8 1 68 1 1 1  1  8 0 68 0 0 1  1
9 1 61 0 0 0  1  9 0 61 0 0 0  1
10 1 64 1 0 0  1 10 0 65 0 0 0  0
11 1 68 1 1 0  1 11 0 69 1 1 0  0
12 1 74 1 0 0  1 12 0 74 1 0 0  0
13 1 67 1 1 0  1 13 0 68 1 0 1  1
14 1 62 1 1 0  1 14 0 62 0 1 0  0
15 1 71 1 1 0  1 15 0 71 1 0 1  1
16 1 83 1 0 1  1 16 0 82 0 0 0  0
17 1 70 0 0 0  1 17 0 70 0 0 1  1
18 1 74 1 0 0  1 18 0 75 0 0 0  0
19 1 70 1 0 0  1 19 0 70 0 0 0  0
20 1 66 1 0 1  1 20 0 66 1 0 0  1
21 1 77 1 0 0  1 21 0 77 1 1 1  1
22 1 66 1 0 1  1 22 0 67 0 0 1  1
23 1 71 1 0 1  0 23 0 72 0 0 0  0
24 1 80 1 0 0  1 24 0 79 0 0 0  0
25 1 64 1 0 0  1 25 0 64 1 0 0  1
26 1 63 1 0 0  1 26 0 63 1 0 1  1
27 1 72 0 1 0  1 27 0 72 0 0 1  0
28 1 57 1 0 0  0 28 0 57 1 0 1  1
29 1 74 0 1 0  1 29 0 74 0 0 0  1
30 1 62 1 0 1  1 30 0 62 1 0 0  1
31 1 73 1 0 1  1 31 0 72 1 0 0  1
32 1 71 1 0 1  1 32 0 71 1 0 1  1
33 1 64 0 0 1  1 33 0 65 1 0 0  1
34 1 63 1 0 0  1 34 0 64 0 0 0  1
35 1 79 1 1 1  1 35 0 78 1 1 1  1
36 1 80 1 0 0  1 36 0 81 0 0 1  1
37 1 82 1 0 1  1 37 0 82 0 0 0  1
38 1 71 1 0 1  1 38 0 71 0 0 1  1
39 1 83 1 0 1  1 39 0 83 0 0 0  1
40 1 61 1 0 1  1 40 0 60 0 0 0  1
41 1 71 1 0 0  1 41 0 71 0 0 0  0
42 1 69 1 0 1  1 42 0 69 0 1 0  1
43 1 77 1 0 0  1 43 0 76 1 0 1  1
44 1 64 1 0 0  0 44 0 64 1 0 0  0
45 1 79 0 1 0  0 45 0 82 1 0 0  1
46 1 72 1 0 0  1 46 0 72 1 0 0  1
47 1 82 1 1 1  1 47 0 81 0 0 0  0
48 1 73 1 0 1  1 48 0 74 1 0 0  1
49 1 69 1 0 0  1 49 0 68 0 0 0  1
50 1 79 1 0 1  1 50 0 79 0 0 0  1
51 1 72 1 0 0  0 51 0 71 1 0 1  1
52 1 72 1 0 1  1 52 0 72 1 0 1  1
53 1 65 1 0 1  1 53 0 67 0 0 0  0
54 1 67 1 0 1  1 54 0 66 1 0 0  1
55 1 64 1 1 0  1 55 0 63 0 0 0  1
56 1 62 1 0 0  0 56 0 63 0 0 0  0
57 1 83 0 1 1  1 57 0 83 0 1 0  0
58 1 81 1 0 0  1 58 0 79 0 0 0  0
59 1 67 1 0 0  1 59 0 66 1 0 1  1
60 1 73 1 1 1  1 60 0 72 1 0 0  1
61 1 67 1 1 0  1 61 0 67 1 1 0  1
62 1 74 1 0 1  1 62 0 75 0 0 0  1
63 1 68 1 1 0  1 63 0 69 1 0 0  1
;

proc logistic;
model case = gall est hyper age nonest /
noint selection=forward details;
run;

data match2;
input id case age est gall hyper nonest @@;
case=2-case;
datalines;
1 1 74 1 0 0  1  1 0 75 0 0 0  0
2 1 67 1 0 0  1  2 0 67 0 0 1  1
3 1 76 1 0 1  1  3 0 76 1 0 1  1
4 1 71 1 0 0  0  4 0 70 1 1 0  1
5 1 69 1 1 0  1  5 0 69 1 0 1  1
6 1 70 1 0 1  1  6 0 71 0 0 0  0
7 1 65 1 1 0  1  7 0 65 0 0 0  0
8 1 68 1 1 1  1  8 0 68 0 0 1  1
9 1 61 0 0 0  1  9 0 61 0 0 0  1
10 1 64 1 0 0  1 10 0 65 0 0 0  0
11 1 68 1 1 0  1 11 0 69 1 1 0  0
12 1 74 1 0 0  1 12 0 74 1 0 0  0
13 1 67 1 1 0  1 13 0 68 1 0 1  1
14 1 62 1 1 0  1 14 0 62 0 1 0  0
15 1 71 1 1 0  1 15 0 71 1 0 1  1
16 1 83 1 0 1  1 16 0 82 0 0 0  0
17 1 70 0 0 0  1 17 0 70 0 0 1  1
18 1 74 1 0 0  1 18 0 75 0 0 0  0
19 1 70 1 0 0  1 19 0 70 0 0 0  0
20 1 66 1 0 1  1 20 0 66 1 0 0  1
21 1 77 1 0 0  1 21 0 77 1 1 1  1
22 1 66 1 0 1  1 22 0 67 0 0 1  1
23 1 71 1 0 1  0 23 0 72 0 0 0  0
24 1 80 1 0 0  1 24 0 79 0 0 0  0
25 1 64 1 0 0  1 25 0 64 1 0 0  1
26 1 63 1 0 0  1 26 0 63 1 0 1  1
27 1 72 0 1 0  1 27 0 72 0 0 1  0
28 1 57 1 0 0  0 28 0 57 1 0 1  1
29 1 74 0 1 0  1 29 0 74 0 0 0  1
30 1 62 1 0 1  1 30 0 62 1 0 0  1
31 1 73 1 0 1  1 31 0 72 1 0 0  1
32 1 71 1 0 1  1 32 0 71 1 0 1  1
33 1 64 0 0 1  1 33 0 65 1 0 0  1
34 1 63 1 0 0  1 34 0 64 0 0 0  1
35 1 79 1 1 1  1 35 0 78 1 1 1  1
36 1 80 1 0 0  1 36 0 81 0 0 1  1
37 1 82 1 0 1  1 37 0 82 0 0 0  1
38 1 71 1 0 1  1 38 0 71 0 0 1  1
39 1 83 1 0 1  1 39 0 83 0 0 0  1
40 1 61 1 0 1  1 40 0 60 0 0 0  1
41 1 71 1 0 0  1 41 0 71 0 0 0  0
42 1 69 1 0 1  1 42 0 69 0 1 0  1
43 1 77 1 0 0  1 43 0 76 1 0 1  1
44 1 64 1 0 0  0 44 0 64 1 0 0  0
45 1 79 0 1 0  0 45 0 82 1 0 0  1
46 1 72 1 0 0  1 46 0 72 1 0 0  1
47 1 82 1 1 1  1 47 0 81 0 0 0  0
48 1 73 1 0 1  1 48 0 74 1 0 0  1
49 1 69 1 0 0  1 49 0 68 0 0 0  1
50 1 79 1 0 1  1 50 0 79 0 0 0  1
51 1 72 1 0 0  0 51 0 71 1 0 1  1
52 1 72 1 0 1  1 52 0 72 1 0 1  1
53 1 65 1 0 1  1 53 0 67 0 0 0  0
54 1 67 1 0 1  1 54 0 66 1 0 0  1
55 1 64 1 1 0  1 55 0 63 0 0 0  1
56 1 62 1 0 0  0 56 0 63 0 0 0  0
57 1 83 0 1 1  1 57 0 83 0 1 0  0
58 1 81 1 0 0  1 58 0 79 0 0 0  0
59 1 67 1 0 0  1 59 0 66 1 0 1  1
60 1 73 1 1 1  1 60 0 72 1 0 0  1
61 1 67 1 1 0  1 61 0 67 1 1 0  1
62 1 74 1 0 1  1 62 0 75 0 0 0  1
63 1 68 1 1 0  1 63 0 69 1 0 0  1
;

proc phreg;
strata id;
model case = gall est hyper age nonest /
selection=forward details rl;
run;

data matched;
input id outcome lung vaccine @@;
outcome=2-outcome;
lung_vac=lung*vaccine;
datalines;
1 1 0 0  1 0 1 0  1 0 0 0  2 1 0 0  2 0 0 0  2 0 1 0
3 1 0 1  3 0 0 1  3 0 0 0  4 1 1 0  4 0 0 0  4 0 1 0
5 1 1 0  5 0 0 1  5 0 0 1  6 1 0 0  6 0 0 0  6 0 0 1
7 1 0 0  7 0 0 0  7 0 0 1  8 1 1 1  8 0 0 0  8 0 0 1
9 1 0 0  9 0 0 1  9 0 0 0 10 1 0 0 10 0 1 0 10 0 0 0
11 1 1 0 11 0 0 1 11 0 0 0 12 1 1 1 12 0 0 1 12 0 0 0
13 1 0 0 13 0 0 1 13 0 1 0 14 1 0 0 14 0 0 0 14 0 0 1
15 1 1 0 15 0 0 0 15 0 0 1 16 1 0 1 16 0 0 1 16 0 0 1
17 1 0 0 17 0 1 0 17 0 0 0 18 1 1 0 18 0 0 1 18 0 0 1
19 1 1 0 19 0 0 1 19 0 0 1 20 1 0 0 20 0 0 0 20 0 0 0
21 1 0 0 21 0 0 1 21 0 0 1 22 1 0 1 22 0 0 0 22 0 1 0
23 1 1 1 23 0 0 0 23 0 0 0 24 1 0 0 24 0 0 1 24 0 0 1
25 1 1 0 25 0 1 0 25 0 0 0 26 1 1 1 26 0 0 0 26 0 0 0
27 1 1 0 27 0 0 1 27 0 0 0 28 1 0 1 28 0 1 0 28 0 0 0
29 1 0 0 29 0 0 0 29 0 1 1 30 1 0 0 30 0 0 0 30 0 0 0
31 1 0 0 31 0 0 0 31 0 0 1 32 1 1 0 32 0 0 0 32 0 0 0
33 1 0 1 33 0 0 0 33 0 0 0 34 1 0 0 34 0 1 0 34 0 0 0
35 1 1 0 35 0 1 1 35 0 0 0 36 1 0 1 36 0 0 0 36 0 0 1
37 1 0 1 37 0 0 0 37 0 0 1 38 1 1 1 38 0 0 1 38 0 0 0
39 1 0 0 39 0 0 1 39 0 0 1 40 1 0 0 40 0 0 0 40 0 1 1
41 1 1 0 41 0 0 0 41 0 0 1 42 1 1 0 42 0 0 0 42 0 0 0
43 1 0 0 43 0 0 1 43 0 0 0 44 1 1 0 44 0 0 0 44 0 0 0
45 1 1 0 45 0 0 0 45 0 0 0 46 1 1 0 46 0 1 1 46 0 0 0
47 1 0 1 47 0 0 0 47 0 0 1 48 1 0 0 48 0 0 0 48 0 0 0
49 1 1 0 49 0 1 0 49 0 1 1 50 1 1 1 50 0 0 0 50 0 0 1
51 1 1 0 51 0 0 1 51 0 0 1 52 1 0 1 52 0 0 0 52 0 0 0
53 1 0 1 53 0 0 1 53 0 0 1 54 1 1 0 54 0 0 0 54 0 0 0
55 1 0 0 55 0 0 1 55 0 0 0 56 1 0 0 56 0 0 0 56 0 1 0
57 1 1 1 57 0 1 0 57 0 0 0 58 1 1 0 58 0 0 1 58 0 0 1
59 1 0 0 59 0 0 0 59 0 1 1 60 1 0 0 60 0 0 0 60 0 0 1
61 1 0 1 61 0 0 0 61 0 0 1 62 1 0 0 62 0 0 0 62 0 0 1
63 1 0 0 63 0 0 1 63 0 0 0 64 1 0 0 64 0 1 0 64 0 0 0
65 1 1 1 65 0 0 0 65 0 1 0 66 1 1 1 66 0 0 1 66 0 1 0
67 1 0 0 67 0 0 0 67 0 0 1 68 1 0 0 68 0 0 1 68 0 0 1
69 1 1 1 69 0 0 1 69 0 0 1 70 1 0 0 70 0 0 1 70 0 1 1
71 1 0 0 71 0 0 0 71 0 0 1 72 1 1 0 72 0 0 0 72 0 0 0
73 1 1 0 73 0 0 1 73 0 0 0 74 1 0 0 74 0 0 0 74 0 0 1
75 1 0 0 75 0 0 1 75 0 0 0 76 1 0 0 76 0 0 0 76 0 0 0
77 1 0 1 77 0 0 0 77 0 0 1 78 1 0 0 78 0 0 1 78 0 0 0
79 1 1 0 79 0 0 1 79 0 0 1 80 1 0 1 80 0 0 0 80 0 0 0
81 1 0 0 81 0 1 1 81 0 0 1 82 1 1 1 82 0 1 0 82 0 0 0
83 1 0 1 83 0 0 0 83 0 0 1 84 1 0 0 84 0 0 0 84 0 0 1
85 1 1 0 85 0 0 0 85 0 0 0 86 1 0 0 86 0 1 1 86 0 1 0
87 1 1 1 87 0 0 0 87 0 0 0 88 1 0 0 88 0 0 0 88 0 0 0
89 1 0 0 89 0 0 1 89 0 1 1 90 1 0 0 90 0 0 0 90 0 0 0
91 1 0 1 91 0 0 0 91 0 0 1  92 1 0 0  92 0 1 1  92 0 0 0
93 1 0 1 93 0 0 0 93 0 1 0  94 1 1 0  94 0 0 0  94 0 0 0
95 1 1 1 95 0 0 1 95 0 0 0  96 1 1 0  96 0 0 1  96 0 0 1
97 1 1 1 97 0 0 0 97 0 0 1  98 1 0 0  98 0 0 0  98 0 1 1
99 1 0 1 99 0 1 1 99 0 0 1 100 1 1 0 100 0 0 0 100 0 0 0
101 1 0 0 101 0 0 0 101 0 0 0 102 1 0 1 102 0 0 0 102 0 0 0
103 1 0 1 103 0 0 0 103 0 0 0 104 1 1 0 104 0 0 1 104 0 1 0
105 1 1 0 105 0 1 0 105 0 0 0 106 1 0 0 106 0 0 0 106 0 0 1
107 1 0 0 107 0 0 1 107 0 0 1 108 1 1 1 108 0 0 0 108 0 0 1
109 1 0 1 109 0 0 0 109 0 0 0 110 1 0 0 110 0 0 0 110 0 0 0
111 1 1 0 111 0 0 1 111 0 0 1 112 1 0 0 112 0 0 1 112 0 0 0
113 1 0 1 113 0 0 0 113 0 1 0 114 1 1 1 114 0 0 1 114 0 0 1
115 1 1 1 115 0 0 1 115 0 0 1 116 1 0 0 116 0 0 1 116 0 1 0
117 1 0 1 117 0 0 0 117 0 0 0 118 1 1 0 118 0 1 0 118 0 0 0
119 1 1 0 119 0 0 0 119 0 0 0 120 1 1 0 120 0 0 0 120 0 0 1
121 1 0 0 121 0 0 1 121 0 0 0 122 1 0 1 122 0 0 0 122 0 0 0
123 1 1 0 123 0 0 0 123 0 1 1 124 1 0 0 124 0 0 1 124 0 0 0
125 1 1 0 125 0 1 0 125 0 0 0 126 1 1 1 126 0 0 0 126 0 0 0
127 1 1 0 127 0 0 1 127 0 0 0 128 1 0 1 128 0 1 0 128 0 0 0
129 1 0 0 129 0 0 0 129 0 1 1 130 1 0 0 130 0 0 0 130 0 0 0
131 1 0 0 131 0 0 0 131 0 0 1 132 1 1 0 132 0 0 0 132 0 0 1
133 1 0 1 133 0 0 0 133 0 0 0 134 1 0 0 134 0 1 0 134 0 0 1
135 1 1 0 135 0 1 1 135 0 0 0 136 1 0 0 136 0 0 0 136 0 0 0
137 1 0 0 137 0 0 0 137 0 0 1 138 1 1 0 138 0 0 0 138 0 0 0
139 1 0 0 139 0 0 0 139 0 0 0 140 1 0 0 140 0 0 1 140 0 1 1
141 1 1 1 141 0 0 0 141 0 0 1 142 1 1 0 142 0 0 0 142 0 0 0
143 1 0 0 143 0 0 1 143 0 1 1 144 1 1 1 144 0 0 1 144 0 0 1
145 1 1 0 145 0 0 1 145 0 0 0 146 1 1 0 146 0 1 0 146 0 0 0
147 1 0 1 147 0 0 0 147 0 0 1 148 1 0 0 148 0 0 1 148 0 0 0
149 1 1 0 149 0 1 0 149 0 1 0 150 1 1 1 150 0 0 0 150 0 0 1
;

proc freq;
tables outcome*lung outcome*vaccine /nocol nopct;
run;

proc phreg;
strata id;
model outcome = lung vaccine lung_vac /
selection=forward details ties=discrete;
run;

proc phreg;
strata id;
model outcome = lung vaccine lung_vac /
selection=forward include=2 details ties=discrete rl;
run;

data animal;
input animal treatment \$ response \$ @@;
if treatment='S' then delete;
else if treatment='C'  then ordtreat=1;
else if treatment='DA' then ordtreat=2;
else if treatment='D1' then ordtreat=3;
else if treatment='D2' then ordtreat=4;
datalines;
1 S no  1 C  no  1 C  no  1 D2 yes 1 D1 yes
2 S no  2 D2 yes 2 C  no  2 D1 yes
3 S no  3 C  yes 3 D1 yes 3 DA no  3 C  no
4 S no  4 C  no  4 D1 yes 4 DA no  4 C  no
5 S yes 5 C  no  5 DA no  5 D1 no  5 C  no
6 S no  6 C  no  6 D1 yes 6 DA no  6 C  no
7 S no  7 C  no  7 D1 yes 7 DA no  7 C  no
8 S yes 8 C  yes 8 D1 yes
;

proc logistic data=animal descending exactonly;
class animal /param=ref;
model response = animal ordtreat;
exact 'parm' ordtreat / estimate=parm;
run;

data animal2;
set animal;
if response = 'yes' then event = 1;
else event = 2;
run;

ods select ResidualChiSq ParameterEstimates;
proc phreg data=animal2;
strata animal;
model event = ordtreat /selection=forward
details ties=discrete slentry=.05;
run;

ods output ExactTests=try1 ExactParmEst=try2;
proc logistic data=animal descending;
class animal /param=ref;
model response = animal ordtreat;
exact 'parm' ordtreat / estimate=both;
run;
proc template;
define table ExactTests2;
parent=Stat.Logistic.Exacttests;
column Label Effect Test Statistic ExactPValue MidPValue;
define ExactPValue;
parent =Stat.Logistic.ExactPValue;
format=D8.6;
end;
end;
data _null_;
title2 'Listing of ExactTests Using a Customized Template';
set try1;
file print ods=(template='ExactTests2');
put _ods_;
run;

```