-
Notifications
You must be signed in to change notification settings - Fork 1
/
overlap_twoarm.sas
124 lines (109 loc) · 2.85 KB
/
overlap_twoarm.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*************************************************************************************
This macro conducts a two arm overlap weight cox survival regression.
It takes as input:
A)dataset- contains the cohort groups (BREAK and REF), unique id (id),
covariates, outcome date, outcome history,
end of followup date (endoffollow), and the start of followup date (t0)
B)history- An indicator of prior history of the disease being examined
Used to exclude those with the disease. May be set to 1 or a date
C)outcome- This contains the date of the outcome
D)psrez- storage of weights for covariate balance evaluation
E)hrrez- storage of hazard ratios
F)surrez- storage of survival probability estimates
G)hdps- dataset with high dimensional covariates in long form
H)pre- dataset with predefined covariates in long form
*************************************************************************************/
%macro disease(history, outcome, dataset, hdps, pre, psrez, hrrez, surrez);
/*Initializes a dataset for survival probability estimation*/
data baseline;
length group $16.;
event=0; time=180;
group="BREAK";output;
group="REF";output;
run;
/*High dimensional covariates*/
data eee;
set &hdps;
length cov $32767.;
retain cov;
cov=catx(' ',cov,_name_);
call symput('hdvs',cov);
run;
/*predefined covariates*/
data eee;
set ⪯
length cov $32767.;
retain cov;
cov=catx(' ',cov,_name_);
call symput('pre',cov);
run;
/*The HD selection is only done once, in an outside program;*/
data model;
set &dataset;
by scrssn;
if a;
if &history<=0;
run;
proc logistic data=model noprint;
class sex race smoke ;
model group(event="BREAK")=
&hdvs ⪯
output out=ps (keep=id group ps_score endoffollow &outcome ) pred=ps_score ;
run;
data &psrez ;
set ;
if group="REF" then ps_&outcome=ps;
if group="BREAK" then ps_&outcome=(1-ps);
drop ps;
run;
data outcome;
set &psrez (where=(ps_&outcome^=.));
if &outcome ^=. and &outcome<=endoffollow then do;
event=1;
time=&outcome -t0;
end;
else do;
event=0;
time=endoffollow-(t0+30);
end;
run;
/*Survival model*/
ods output hazardratios=hr_out;
proc phreg data=outcome covs(aggregate);
class group (ref="REF");
model time*event(0)=group;
hazardratio group/diff=pairwise;
weight ps_&outcome;
id id;
baseline out=sur_out covariates=baseline survival=sur upper=suru lower=surl;
run;
data hr;
set hr_out;
outcome="&outcome";
run;
data sur;
set sur_out;
outcome="&outcome";
run;
data &hrrez;
set &hrrez hr;
run;
data &surrez;
set &surrez sur;
run;
%mend;
*Storage for hazard ratios;
data HR;
length outcome $50;
set _null_;
run;
*Storage for survival probability estimates;
data SUR;
length outcome $50;
set _null_;
run;
*storage of weights;
data PS;
set cohort (keep=id);
run;
%disease (history, outcome, dataset, hdps, pre, PS, HR,SUR);