-
Notifications
You must be signed in to change notification settings - Fork 1
/
shift_table.sas
327 lines (291 loc) · 9.56 KB
/
shift_table.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
data ADSL;
length USUBJID $ 3;
label USUBJID = "Unique Subject Identifier"
TRTPN = "Planned Treatment (N)";
input USUBJID $ TRTPN @@;
datalines;
101 1 102 0 103 0 104 1 105 0 106 0 107 1 108 1 109 1 110 1
;
run;
**** INPUT SAMPLE LABORATORY DATA AS SDTM LB DATA;
data LB;
label USUBJID = "Unique Subject Identifier"
VISITNUM = "Visit Number"
LBCAT = "Category for Lab Test"
LBTEST = "Laboratory Test"
LBSTRESU = "Standard Units"
LBSTRESN = "Numeric Result/Finding in Standard Units"
LBSTNRLO = "Reference Range Lower Limit-Std Units"
LBSTNRHI = "Reference Range Upper Limit-Std Units"
LBNRIND = "Reference Range Indicator";
input USUBJID $ 1-3 VISITNUM 6 LBCAT $ 9-18 LBTEST $ 20-29
LBSTRESU $ 32-35 LBSTRESN 38-41 LBSTNRLO 45-48
LBSTNRHI 52-55 LBNRIND $ 59;
datalines;
101 0 HEMATOLOGY HEMATOCRIT % 31 35 49 L
101 1 HEMATOLOGY HEMATOCRIT % 39 35 49 N
101 2 HEMATOLOGY HEMATOCRIT % 44 35 49 N
101 0 HEMATOLOGY HEMOGLOBIN g/dL 11.5 11.7 15.9 L
101 1 HEMATOLOGY HEMOGLOBIN g/dL 13.2 11.7 15.9 N
101 2 HEMATOLOGY HEMOGLOBIN g/dL 14.3 11.7 15.9 N
102 0 HEMATOLOGY HEMATOCRIT % 39 39 52 N
102 1 HEMATOLOGY HEMATOCRIT % 39 39 52 N
102 2 HEMATOLOGY HEMATOCRIT % 44 39 52 N
102 0 HEMATOLOGY HEMOGLOBIN g/dL 11.5 12.7 17.2 L
102 1 HEMATOLOGY HEMOGLOBIN g/dL 13.2 12.7 17.2 N
102 2 HEMATOLOGY HEMOGLOBIN g/dL 18.3 12.7 17.2 H
103 0 HEMATOLOGY HEMATOCRIT % 50 35 49 H
103 1 HEMATOLOGY HEMATOCRIT % 39 35 49 N
103 2 HEMATOLOGY HEMATOCRIT % 55 35 49 H
103 0 HEMATOLOGY HEMOGLOBIN g/dL 12.5 11.7 15.9 N
103 1 HEMATOLOGY HEMOGLOBIN g/dL 12.2 11.7 15.9 N
103 2 HEMATOLOGY HEMOGLOBIN g/dL 14.3 11.7 15.9 N
104 0 HEMATOLOGY HEMATOCRIT % 55 39 52 H
104 1 HEMATOLOGY HEMATOCRIT % 45 39 52 N
104 2 HEMATOLOGY HEMATOCRIT % 44 39 52 N
104 0 HEMATOLOGY HEMOGLOBIN g/dL 13.0 12.7 17.2 N
104 1 HEMATOLOGY HEMOGLOBIN g/dL 13.3 12.7 17.2 N
104 2 HEMATOLOGY HEMOGLOBIN g/dL 12.8 12.7 17.2 N
105 0 HEMATOLOGY HEMATOCRIT % 36 35 49 N
105 1 HEMATOLOGY HEMATOCRIT % 39 35 49 N
105 2 HEMATOLOGY HEMATOCRIT % 39 35 49 N
105 0 HEMATOLOGY HEMOGLOBIN g/dL 13.1 11.7 15.9 N
105 1 HEMATOLOGY HEMOGLOBIN g/dL 14.0 11.7 15.9 N
105 2 HEMATOLOGY HEMOGLOBIN g/dL 14.0 11.7 15.9 N
106 0 HEMATOLOGY HEMATOCRIT % 53 39 52 H
106 1 HEMATOLOGY HEMATOCRIT % 50 39 52 N
106 2 HEMATOLOGY HEMATOCRIT % 53 39 52 H
106 0 HEMATOLOGY HEMOGLOBIN g/dL 17.0 12.7 17.2 N
106 1 HEMATOLOGY HEMOGLOBIN g/dL 12.3 12.7 17.2 L
106 2 HEMATOLOGY HEMOGLOBIN g/dL 12.9 12.7 17.2 N
107 0 HEMATOLOGY HEMATOCRIT % 55 39 52 H
107 1 HEMATOLOGY HEMATOCRIT % 56 39 52 H
107 2 HEMATOLOGY HEMATOCRIT % 57 39 52 H
107 0 HEMATOLOGY HEMOGLOBIN g/dL 18.0 12.7 17.2 N
107 1 HEMATOLOGY HEMOGLOBIN g/dL 18.3 12.7 17.2 H
107 2 HEMATOLOGY HEMOGLOBIN g/dL 19.2 12.7 17.2 H
108 0 HEMATOLOGY HEMATOCRIT % 40 39 52 N
108 1 HEMATOLOGY HEMATOCRIT % 53 39 52 H
108 2 HEMATOLOGY HEMATOCRIT % 54 39 52 H
108 0 HEMATOLOGY HEMOGLOBIN g/dL 15.0 12.7 17.2 N
108 1 HEMATOLOGY HEMOGLOBIN g/dL 18.0 12.7 17.2 H
108 2 HEMATOLOGY HEMOGLOBIN g/dL 19.1 12.7 17.2 H
109 0 HEMATOLOGY HEMATOCRIT % 39 39 52 N
109 1 HEMATOLOGY HEMATOCRIT % 53 39 52 H
109 2 HEMATOLOGY HEMATOCRIT % 57 39 52 H
109 0 HEMATOLOGY HEMOGLOBIN g/dL 13.0 12.7 17.2 N
109 1 HEMATOLOGY HEMOGLOBIN g/dL 17.3 12.7 17.2 H
109 2 HEMATOLOGY HEMOGLOBIN g/dL 17.3 12.7 17.2 H
110 0 HEMATOLOGY HEMATOCRIT % 50 39 52 N
110 1 HEMATOLOGY HEMATOCRIT % 51 39 52 N
110 2 HEMATOLOGY HEMATOCRIT % 57 39 52 H
110 0 HEMATOLOGY HEMOGLOBIN g/dL 13.0 12.7 17.2 N
110 1 HEMATOLOGY HEMOGLOBIN g/dL 18.0 12.7 17.2 H
110 2 HEMATOLOGY HEMOGLOBIN g/dL 19.0 12.7 17.2 H
;
run;
;
run;
proc sort
data = lb;
by usubjid lbcat lbtest lbstresu visitnum;
run;
proc sort
data = adsl;
by usubjid;
run;
**** MERGE TREATMENT INFORMATION WITH LAB DATA.;
data lb;
merge adsl(in = inadsl) lb(in = inlb);
by usubjid;
if inlb and not inadsl then
put "WARN" "ING: Missing treatment assignment for subject "
usubjid=;
if inadsl and inlb;
run;
*** carry forward baseline flg;
proc sort data=lb;
by usubjid lbcat lbtest lbstresu visitnum;
run;
data lb;
set lb;
by usubjid lbcat lbtest lbstresu visitnum;
retain base;
if first.lbtest then base = lbnrind;
if visitnum > 0;
shift=catx(' ', base, 'to', lbnrind);
run;
proc sort data=lb;
by trtpn visitnum lbcat lbtest shift;
run;
proc sql;
create table freq as
select distinct trtpn, visitnum, lbcat, lbtest, shift, count(distinct usubjid)as n,base,lbnrind from lb
group by trtpn, visitnum, lbcat, lbtest, shift;
run;
***informat;
proc format;
invalue shift
'L to L'=1
'L to N'=2
'L to H'=3
'N to L'=4
'N to N'=5
'N to H'=6
'H to L'=7
'H to N'=8
'H to H'=9
;
run;
data freq;
set freq;
cat=input(shift,shift.);
run;
data freq1;
set freq;
if lbtest='HEMATOCRIT';
run;
data freq2;
set freq;
if lbtest='HEMOGLOBIN';
run;
***dummy;
data dummy;
do visitnum=1 to 2;
do trtpn=0 to 1;
do cat=1 to 9;
output;
end;
end;
end;
run;
***merge dummy and freq table;
proc sort data=dummy;
by visitnum trtpn cat;
run;
proc sort data=freq1;
by visitnum trtpn cat;
run;
proc sort data=freq2;
by visitnum trtpn cat;
run;
proc sql;
select sum(n) into :n1 -:n4 from freq1
group by visitnum, trtpn;
quit;
proc sql;
select sum(n) into :n5 -:n8 from freq2
group by visitnum, trtpn;
quit;
data merg1;
merge dummy(in=indummy) freq1;
by visitnum trtpn cat;
length per $100;
if indummy;
if n=. then per=' 0( 0%)';
else if visitnum=1 and trtpn=0 then per=put(n,3.)||'('||put(n/&n1*100,3.)||'%)';
else if visitnum=1 and trtpn=1 then per=put(n,3.)||'('||put(n/&n2*100,3.)||'%)';
else if visitnum=2 and trtpn=0 then per=put(n,3.)||'('||put(n/&n3*100,3.)||'%)';
else if visitnum=2 and trtpn=1 then per=put(n,3.)||'('||put(n/&n4*100,3.)||'%)';
run;
data merg2;
merge dummy(in=indummy) freq2;
by visitnum trtpn cat;
length per $100;
if indummy;
if n=. then per=' 0( 0%)';
else if visitnum=1 and trtpn=0 then per=put(n,3.)||'('||put(n/&n5*100,3.)||'%)';
else if visitnum=1 and trtpn=1 then per=put(n,3.)||'('||put(n/&n6*100,3.)||'%)';
else if visitnum=2 and trtpn=0 then per=put(n,3.)||'('||put(n/&n7*100,3.)||'%)';
else if visitnum=2 and trtpn=1 then per=put(n,3.)||'('||put(n/&n8*100,3.)||'%)';
run;
data merg1;
set merg1;
if cat=1 then do;base='L';lbnrind='L';end;
if cat=2 then do;base='L';lbnrind='N';end;
if cat=3 then do;base='L';lbnrind='H';end;
if cat=4 then do;base='N';lbnrind='L';end;
if cat=5 then do;base='N';lbnrind='N';end;
if cat=6 then do;base='N';lbnrind='H';end;
if cat=7 then do;base='H';lbnrind='L';end;
if cat=8 then do;base='H';lbnrind='N';end;
if cat=9 then do;base='H';lbnrind='H';end;
lbcat='HEMATOLOGY';
lbtest='HEMATOCRIT';
run;
proc sort data=merg1;
by visitnum trtpn lbcat lbtest lbnrind;
run;
proc transpose data=merg1 out=data1;
by visitnum trtpn lbcat lbtest lbnrind;
id base;
var per;
run;
data merg2;
set merg2;
if cat=1 then do;base='L';lbnrind='L';end;
if cat=2 then do;base='L';lbnrind='N';end;
if cat=3 then do;base='L';lbnrind='H';end;
if cat=4 then do;base='N';lbnrind='L';end;
if cat=5 then do;base='N';lbnrind='N';end;
if cat=6 then do;base='N';lbnrind='H';end;
if cat=7 then do;base='H';lbnrind='L';end;
if cat=8 then do;base='H';lbnrind='N';end;
if cat=9 then do;base='H';lbnrind='H';end;
lbcat='HEMATOLOGY';
lbtest='HEMATOCRIT';
run;
data merg1label;
set merg1;
if trtpn=0 and base='H' then posi=1;
if trtpn=0 and base='N' then posi=2;
if trtpn=0 and base='L' then posi=3;
if trtpn=1 and base='H' then posi=4;
if trtpn=1 and base='N' then posi=5;
if trtpn=1 and base='L' then posi=6;
run;
proc sort data=merg1label;
by lbcat lbtest visitnum lbnrind;
run;
proc transpose data=merg1label out=merg1tran;
by lbcat lbtest visitnum lbnrind;
id posi;
var per;
run;
data final1;
set merg1tran;
drop _name_ ;
if lbnrind='L' then po=1;
else if lbnrind='N' then po=2;
else po=3;
run;
proc sort data=final1 out=final1(drop= po);
by visitnum po;
run;
data merg2label;
set merg2;
if trtpn=0 and base='H' then posi=1;
if trtpn=0 and base='N' then posi=2;
if trtpn=0 and base='L' then posi=3;
if trtpn=1 and base='H' then posi=4;
if trtpn=1 and base='N' then posi=5;
if trtpn=1 and base='L' then posi=6;
run;
proc sort data=merg2label;
by lbcat lbtest visitnum lbnrind;
run;
proc transpose data=merg2label out=merg2tran;
by lbcat lbtest visitnum lbnrind;
id posi;
var per;
run;
data final2;
set merg2tran;
drop _name_ ;
if lbnrind='L' then po=1;
else if lbnrind='N' then po=2;
else po=3;
run;
proc sort data=final2 out=final2(drop= po);
by visitnum po;
run;