-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathds.sas
345 lines (296 loc) · 9.85 KB
/
ds.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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# Disposition_table
Table summarizes the disposition events in a study, with basic demography details
/*Final code*/
libname adam "/folders/myfolders/sasuser.v94/adam";
proc sql;/* storing all the denominatores*/
select count(distinct subjid) into:P1
from adam.adsl
where randfl="Y";
select count(distinct subjid) into:g1
from adam.adsl
where trsqptcd ="ABFCED" and randfl="Y";
select count(distinct subjid) into:g2
from adam.adsl
where trsqptcd ="BCADFE" and randfl="Y";
select count(distinct subjid) into:g3
from adam.adsl
where trsqptcd ="CDBEAF" and randfl="Y";
select count(distinct subjid) into:g4
from adam.adsl
where trsqptcd ="DECFBA" and randfl="Y";
select count(distinct subjid) into:g5
from adam.adsl
where trsqptcd ="EFDACB" and randfl="Y";
select count(distinct subjid) into:g6
from adam.adsl
where trsqptcd ="FAEBDC" and randfl="Y";
quit;
/*deriving row1*/
data myadsl(keep= subjid trsqptcd randfl complfl);
set adam.adsl;
where randfl="Y";
run;
proc freq data =myadsl noprint;
tables trsqptcd/out= count(drop=percent);
run;
proc transpose data=count out=count_transformed(drop=_name_ _label_);/* row1 */
id trsqptcd;
var count;
run;
/* derving event variable for row1*/
data row1;
set count_transformed;
length EventN $4 Event $50;
EventN="1";Event="Subjects in the Randomized Population";
run;
/**************************************************************/
data complfl; /* row2*/
set myadsl;
where complfl="Y";
run;
proc freq data = complfl noprint;
tables trsqptcd/out= count_complfl(drop=percent);
run;
proc transpose data=count_complfl out=count_complfl_transformed(drop=_name_ _label_);
id trsqptcd;
var count;
run;
data row2;
set count_complfl_transformed;
EventN="2";Event="Subjects who Completed the Study";
run;
/****************************************************************/
data adsp(keep = subjid randfl aperiod aperiodc trseqpcd);/* derive row3 to row9*/
set adam.adsp;
where (aperiod ne 1) and (aperiod ne 2) and randfl="Y";
run;
data adsl(keep=subjid randfl trseqpcd trsqptcd);/* subsetting from adsl and adsp datasets for treatment period*/
set adam.adsl;
where randfl eq "Y";
run;
proc sort data=adsp out= adsp_sorted;
by subjid trseqpcd randfl aperiod aperiodc ;
run;
proc sort data=adsl out= adsl_sorted;
by subjid trseqpcd randfl;
run;
data adsl_adsp(keep =subjid trsqptcd aperiodc);
merge adsl_sorted adsp_sorted;
by subjid trseqpcd randfl;
run;
proc sort data= adsl_adsp out=test;/* sort the merged dataset, number of subjects needed by treatment period*/
by subjid;
run;
proc freq data=test noprint;
by subjid;
tables aperiodc*trsqptcd/ out=count_row3(drop=percent);
run;
proc freq data=count_row3 noprint;
weight count;
tables aperiodc*trsqptcd/ out= test_1(drop=percent);
run;
proc sort data=test_1;
by aperiodc;
run;
proc transpose data=test_1 out=test_2(drop=_name_ _label_);
by aperiodc ;
id trsqptcd;
var count;
run;
/* setting all 3 rows*/
data row3;
set test_2;
Length EventN $4 Event $50;
if aperiodc="Treatment Period 1" then do;EventN="3";
Event="Subjects who completed Treatment Period 1";end;
if aperiodc="Treatment Period 2" then do;EventN="4";
Event="Subjects who completed Treatment Period 2";end;
if aperiodc="Treatment Period 3" then do;EventN="5";
Event="Subjects who completed Treatment Period 3";end;
if aperiodc="Treatment Period 4" then do;EventN="6";
Event="Subjects who completed Treatment Period 4";
end;
if aperiodc="Treatment Period 5" then do;EventN="7";
Event="Subjects who completed Treatment Period 5";end;
if aperiodc="Treatment Period 6" then do;EventN="8";
Event="Subjects who completed Treatment Period 6";end;
drop aperiodc;
run;
/******************* set all the 3 rows*/
/*data ;
set row1 row2 row3;
run;*/
/******* deriving row9 from adsp*/
data adsp(keep = subjid randfl discfl trseqpcd);
set adam.adsp;
where (aperiod ne 1) and (aperiod ne 2) ;
run;
data adsl(keep=subjid randfl trseqpcd trsqptcd);
set adam.adsl;
where randfl eq "Y" ;
run;
proc sort data=adsp out= adsp_sorted;
by subjid trseqpcd randfl ;
run;
proc sort data=adsl out= adsl_sorted;
by subjid trseqpcd randfl;
run;
data adsl_adsp(keep =subjid discfl randfl trsqptcd );/* has treatment sequence taken from adsl*/
merge adsl_sorted adsp_sorted;
by subjid trseqpcd ;
run;
/* subsetting for records who have discontinued*/
data test1(drop=randfl);
set adsl_adsp;
where discfl="Y";
run;
proc freq data=test1 noprint;
tables trsqptcd/ out= test2(drop=percent);
run;
proc transpose data=test2 out=test2_transposed(drop=_name_ _label_);
id trsqptcd;
var count;
run;
data row9;
set test2_transposed;
length EventN $4 Event $50;
EventN="9";
Event="Subjects who Discontinued Early";
run;
/**********************************end of part1****************************/
/* deriving part2*/
data adsp(keep = subjid randfl discfl preason aperiod trseqpcd);
set adam.adsp;
where (aperiod ne 1) and (aperiod ne 2) and discfl="Y";
run;
data adsl(keep=subjid randfl trseqpcd complfl trsqptcd);
set adam.adsl;
where randfl eq "Y" and complfl="N";
run;
proc sort data=adsp out= adsp_sorted;
by subjid trseqpcd ;
run;
proc sort data=adsl out= adsl_sorted;
by subjid trseqpcd ;
run;
data adsl_adsp(keep =subjid_N trsqptcd preason );/* has treatment sequence taken from adsl*/
merge adsl_sorted adsp_sorted;
by subjid trseqpcd ;
subjid_N=input(subjid, 8.);
run;
proc format; /*format for preloadfmt applied on preason*/
value $reason
"Occurence Of Intolerable Adverse Event" ="Adverse Event"
"Withdrawal Of Consent" ="Withdrawal of Consent"
"Lost to Follow-up" ="Lost to Follow-up"
"Administrative Reasons"="Administrative Reasons"
"Major Violation of the Protocol"="Major Violation of the Protocol"
"Physician Decision" ="Physician Decision"
"Pregnancy" ="Pregnancy"
"Non-Compliance"="Non-compliance"
"Termination of the Study"="Termination of the Study"
"Death" ="Death"
"Other"="Other"
;
quit;
proc means data=adsl_adsp noprint n nway completetypes;
class trsqptcd;
class preason/preloadfmt ;
format preason $reason. ;
var subjid_N;
output out= means_1 (DROP= _TYPE_ _FREQ_) n=n1;
run;
proc sort data= means_1;
by preason;
run;
proc transpose data= means_1 out= means_2(drop=_name_ );
by preason;
id trsqptcd;
var n1;
run;
/* rename Preason as Event*/
proc format;
value $event_number
"Adverse Event"="11"
"Withdrawal of Consent"="12"
"Lost to Follow-up" ="13"
"Administrative Reasons" ="14"
"Major Violation of the Protocol"="15"
"Physician Decision"="16"
"Pregnancy"="17"
"Non-compliance"="18"
"Termination of the Study"="19"
"Death"="20"
"Other"="21"
;
quit;
data row11;
set means_2;
length Event $50 EventN $4;
Event=put(preason,$reason.);/* equating formatted preason as Event*/
EventN=put(Event, $event_number.);
drop preason;
run;
data temp1;
set row1 row2 row3 row9 row11;
run;
data temp2;
set temp1;/* code to handle missing values*/
if(ABFCED eq .) then do; ABFCED=0; end;
if(BCADFE eq .) then do; BCADFE=0; end;
if(CDBEAF eq .) then do; CDBEAF=0; end;
if(DECFBA eq .) then do; DECFBA=0; end;
if(EFDACB eq .) then do; EFDACB=0; end;
if(FAEBDC eq .) then do; FAEBDC=0; end;
Total= (ABFCED+BCADFE+CDBEAF+DECFBA+EFDACB+FAEBDC);
run;
/* calculating percentages*/
data final;
set temp2;
length ABFCED_N $20 BCADFE_N $20 CDBEAF_N $20 DECFBA_N $20 EFDACB_N $20 FAEBDC_N $20 total_new $20;
if EventN eq "1" then do;
ABFCED_N=put(ABFCED,4.); BCADFE_N=put(BCADFE,4.); CDBEAF_N=put(CDBEAF,4.);
DECFBA_N=put(DECFBA,4.); EFDACB_N=put(EFDACB,4.); FAEBDC_N=put(FAEBDC,4.);
Total_new=put(total,4.);
end;
else do;
if ABFCED eq 0 then do; ABFCED_N=put(ABFCED, 4.); end;
if (ABFCED ne 0 and ABFCED ne &g1 ) then do;
ABFCED_N=compress(put(ABFCED, 4.) || '(' || put(((ABFCED/&g1)*100),8.1) || ')') ;end;
if(ABFCED ne 0 and ABFCED eq &g1 ) then do;
ABFCED_N=compress(put(ABFCED, 4.) || '(' || put(((ABFCED/&g1)*100),8.) || ')') ;end;
if BCADFE eq 0 then do; BCADFE_N=put(BCADFE, 4.); end;
if ( BCADFE ne 0 and BCADFE ne &g2) then do;
BCADFE_N=compress(put(BCADFE, 4.) || '(' || put(((BCADFE/&g1)*100),8.1) || ')') ;end;
if(( BCADFE ne 0 and BCADFE eq &g2)) then do;
BCADFE_N=compress(put(BCADFE, 4.) || '(' || put(((BCADFE/&g1)*100),8.) || ')') ;end;
if CDBEAF eq 0 then do; CDBEAF_N=put(CDBEAF, 4.); end;
if ( CDBEAF ne 0 and CDBEAF ne &g3) then do;
CDBEAF_N=compress(put(CDBEAF, 4.) || '(' || put(((CDBEAF/&g3)*100),8.1) || ')') ;end;
if(( CDBEAF ne 0 and CDBEAF eq &g3)) then do;
CDBEAF_N=compress(put(CDBEAF, 4.) || '(' || put(((CDBEAF/&g1)*100),8.) || ')') ;end;
if DECFBA eq 0 then do; DECFBA_N=put(DECFBA, 4.); end;
if ( DECFBA ne 0 and DECFBA ne &g1) then do;
DECFBA_N=compress(put(DECFBA, 4.) || '(' || put(((DECFBA/&g1)*100),8.1) || ')') ;end;
if(( DECFBA ne 0 and DECFBA eq &g1)) then do;
DECFBA_N=compress(put(DECFBA, 4.) || '(' || put(((DECFBA/&g1)*100),8.) || ')') ;end;
if EFDACB eq 0 then do; EFDACB_N=put(EFDACB, 4.); end;
if ( EFDACB ne 0 and EFDACB ne &g1) then do;
EFDACB_N=compress(put(EFDACB, 4.) || '(' || put(((EFDACB/&g1)*100),8.1) || ')') ;end;
if(( EFDACB ne 0 and EFDACB eq &g1)) then do;
EFDACB_N=compress(put( EFDACB,4.) || '(' || put(((EFDACB/&g1)*100),8.) || ')') ;end;
if FAEBDC eq 0 then do; FAEBDC_N=put(FAEBDC, 4.); end;
if ( FAEBDC ne 0 and FAEBDC ne &g1) then do;
FAEBDC_N=compress(put(FAEBDC, 4.) || '(' || put(((FAEBDC/&g1)*100),8.1) || ')') ;end;
if(( FAEBDC ne 0 and FAEBDC eq &g1)) then do;
FAEBDC_N=compress(put(FAEBDC,4.) || '(' || put(((FAEBDC/&g1)*100),8.) || ')') ;end;
if total eq 0 then do; total_new=compress(put(total, 4.)); end;
if ( total ne 0 and total ne &p1) then do;
total_new=compress(put(total, 4.) || '(' || put(((total/&p1)*100),8.1) || ')') ;end;
if(( total ne 0 and total eq &p1)) then do;
total_new=compress(put(total,4.) || '(' || put(((total/&p1)*100),8.) || ')') ;end;
end;/* else do loop completes, copmutes for all events ne 1*/
drop ABFCED BCADFE CDBEAF DECFBA EFDACB FAEBDC total;
rename ABFCED_N=ABFCED BCADFE_N=BCADFE CDBEAF_N=CDBEAF DECFBA_N=DECFBA
EFDACB_N=EFDACB FAEBDC_N=FAEBDC total_new=Total;
run;