Hosp All
Hosp All
*******************************************************************************;
*** Read in ADSL ADHOSP ADAE Dataset ***;
*******************************************************************************;
PROC SQL;
select distinct dcutdt into: dcutdt
from adsl;
quit;
%put &dcutdt;
data hosp;
merge adsl(in=a) adhosp(in=b);
by usubjid;
if a and b;
run;
data firsthosp;
set hosp;
by usubjid hostdt;
if first.usubjid;
run;
data hosp2;
set hosp1;
by usubjid hostdt;
if first.usubjid then seq=1;
else seq+1;
if last.usubjid;
length seqcat $200;***making category 1 or >1, for using later for counting***;
if seq=1 then seqcat='Patients with 1 hospitalization';
else if seq>1 then seqcat='Patients with >1 hospitalizations';
run;
data durcat;
set firsthosp;
by usubjid hostdt hoendt;
length durcat $200;format hostdt1 hostdt2 hostdt3 hostdt4 hostdt5 date9.;
retain hostdt1 hostdt2 hostdt3 hostdt4 hostdt5;
hostdt1=trtsdt+30.4375-1;
hostdt2=(hostdt1+30.4375);
hostdt3=(hostdt2+30.4375);
hostdt4=(hostdt3+30.4375);
hostdt5=(hostdt4+30.4375);
hostdt6=(hostdt5+30.4375);
data alivestay_;
merge hosp1(in=a) adsl(in=b);
if a and b;
by usubjid;
run;
proc sort nodupkey;by usubjid;run;
data alivestay;
set alivestay_;
dthdt_= dthdt; trtsdt_= trtsdt;
if DTHDT_ ne . and TRTSDT_ <= DTHDT_ <= TRTSDT_+89 then alive_stay= DTHDT_ -
TRTSDT_ +1;
Else alive_stay= 90;
run;
data hosp11;
set hosp1;
if hostdt<trtsdt then hostdt=trtsdt;
if hostdt >=trtsdt;
if hoendt=. then hoendt='18mar2021'd;
run;
data Totdays;
set hosp11;
run;
data d190_;
set hosp1/*(rename=(trta=trt01a trtan=trt01an))*/;
if hoendt ne . then do;
if hostdy>90 or hoendt < trtsdt then delete;****hosp starts after day90, deleted**;
end;
if hostdt<trtsdt then hostdt=trtsdt;
***resetting hosp start date if before Day 1, hosp count only from trtsdt****;
if hoendt>(trtsdt+89) then hoendt=trtsdt+89;****keeping enddate as upto D90 days**;
/*keep usubjid hostdt hoendt trt01a trt01an;*/
run;
data d190;
set d190_;
if hostdt<trtsdt then hostdt=trtsdt;
if hostdt >=trtsdt;
if hoendt=. then hoendt='18mar2021'd;
if hoendt>(trtsdt+89) then hoendt=trtsdt+89;
run;
data chk_;
set hosp1/*(rename=(trta=trt01a trtan=trt01an))*/;
where hostdy >=1 ;
keep usubjid hostdt hoendt trt01a trt01an trtsdt;
run;
data chk;
set chk_;
if hostdt<trtsdt then hostdt=trtsdt;
if hostdt >=trtsdt;
if hoendt=. then hoendt='18mar2021'd;
if hoendt>(trtsdt+89) then hoendt=trtsdt+89;
run;
data excludeaza_;
set hosp1/*(rename=(trta=trt01a trtan=trt01an))*/;
where ^(INDEX(HORESP,'AZA')>0 OR INDEX(HORESP,'Aza')>0);
/* keep usubjid hostdt hoendt trt01a trt01an horesp trtsdt;*/
run;
data excludeaza;
set excludeaza_;
if hostdt<trtsdt then hostdt=trtsdt;
if hostdt >=trtsdt;
if hoendt=. then hoendt='18mar2021'd;
if hoendt>(trtsdt+89) then hoendt=trtsdt+89;
run;
%macro hospital_eoh(dataset_in=,dataset_out=);
/* Step 1 - Number the sorted data for EoH */
data data_1;
set &dataset_in;
by usubjid hostdt hoendt;
retain n;
if first.usubjid then n=0;
n=n+1;
run;
/* Step 2 - Transpose the variables in hostdt and hoendt for EoH */
%macro eoh(inA=,inB=,outA=,from=,to=);
proc transpose data=&inA out=&outA (drop=_name_) prefix=&to;
by usubjid;
var &from;
run;
%mend;
%eoh(inA=data_1,outA=admit,from=hostdt,to=hostdt)
%eoh(inA=data_1,outA=dschg,from=hoendt,to=hoendt)
/* Step 3 - Combine the transposed admission & discharged date & main files */
%macro join(inA=, inB=, outA=, b=, xvar=);
data &outA;
merge &inA (in=x) &inB (in=y drop=&xvar);
by &b;
if x and y; run;
%mend;
%join(inA=admit, inB=dschg, outA=Admit_dschg, b=usubjid)
%join(inA=data_1, inB=Admit_dschg, outA=hospital_adm_dschg, b=usubjid)
proc sql;
select left(trim(put(MAX(count),5.))) into: Idy from
(select count(*) as count
from hospital_adm_dschg
group by usubjid);
QUIT;
%PUT &Idy;
proc sort data=hospital_adm_dschg;
by usubjid hostdt hoendt;
run;
/* Step 4 - Compute and assign EoH & Hospitalization Types */
data data_2 (drop= i diff done eoh2 seq2 hostdt1-hostdt&Idy hoendt1-
hoendt&Idy);
set hospital_adm_dschg;
by usubjid hostdt hoendt;
where n LE &Idy;
run;
proc sort data=data_2;
by usubjid eoh1 hostdt hoendt;
run;
/* Step 5 - Compute other variables (i.e. LOS) & prepare the final output */
DATA data_3; retain usubjid hostdt hoendt n eoh1 count nest trans los
/*EOH_LOS*/; SET data_2;
by usubjid eoh1 hostdt hoendt;
RETAIN count; count + 1;
IF FIRST.eoh1 THEN count = 1;
rename eoh1 = eoh;
rename n = total_hosp;
rename los = hosp_los;
drop seq;
run;
data data_nonest;
set data_3;
IF nest ^= 1;
run;
DATA data_4;
SET data_nonest;
BY usubjid EOH;
IF FIRST.EOH OR LAST.EOH;
hoendt_first = lag(hoendt);
hostdt_first = lag(hostdt);
usubjid_first = lag(usubjid);
EOH_first = lag(EOH);
IF usubjid = usubjid_first AND EOH = EOH_first THEN hostdt = hostdt_first;
IF LAST.eoh;
eoh_los = hoendt - hostdt + 1;
format hostdt hoendt date9.;
KEEP usubjid EOH eoh_los count;
RUN;
PROC SQL;
CREATE TABLE &dataset_out AS
SELECT a.*, b.eoh_los
FROM data_3 a LEFT JOIN data_4 b
ON a.usubjid = b.usubjid AND a.eoh = b.eoh
ORDER BY usubjid, EOH, hostdt, hoendt;
QUIT;
%mend hospital_eoh;
%hospital_eoh(dataset_in=Totdays,dataset_out=Totdays1)
%hospital_eoh(dataset_in=d190,dataset_out=d190out)
%hospital_eoh(dataset_in=chk,dataset_out=chk1)
%hospital_eoh(dataset_in=excludeaza,dataset_out=excludeazaout)
data exclude_beforeday1;
set chk1;
if count=1 and eoh_los>=1;
run;
data excludeazaout1;
set excludeazaout;
if count=1 and eoh_los>=1;
run;
data d190out1;
set d190out;
if count=1 and eoh_los>=1;
run;
data Totdayshosp;
set Totdays1;
if count=1 and eoh_los>=1;
run;
proc sql;
create table d190cnt as
select trt01an, trt01a, 5 as section, 20.5 as sord,
' day1-90' as text length=200,sum(eoh_los) as numer
from d190out1
group by trt01an, trt01a, section, sord, text;
quit;
proc sql;
create table alivecnt as
select trt01an, trt01a, 5 as section, 20.5 as sord,
'Total days alive during day 1 - day 90' as text length=200,sum(alive_stay) as
denom
from alivestay
where alive_stay ne . /*and durcatn in(2,3,4)*/
group by trt01an, trt01a, section, sord, text;
quit;
data aliveprcnt;
merge alivecnt(in=a) d190cnt(in=b);
format per 5.1;
by trt01a trt01an;
if a and b;
per= (numer/denom)*100;
run;
data hosp3;
length daysdur $40.;
set hosp11;
by usubjid hostdt hoendt;
data hosp33;
set hosp3;
if hoendt<hostdt then delete;
run;
/* 8 section*/
data firsthospdays;
set hosp3;
where tth=1;
firsthospdays=(hostdt-trtsdt)+1;
run;
union
select trt01an, trt01a, 1 as section, 11 as sord, ' First hospitalization began
before Day 1' as text length=200,count(distinct usubjid) as smaln
from firsthosp
where hostdt<trtsdt
group by trt01an, trt01a, section, sord, text
union
select trt01an, trt01a, 1 as section, 12 as sord, ' First hospitalization began
on Day 1' as text length=200,count(distinct usubjid) as smaln
from firsthosp
where hostdt=trtsdt
group by trt01an, trt01a, section, sord, text
union
select trt01an, trt01a, 1 as section, 13 as sord, ' First hospitalization began
after Day 1' as text length=200,count(distinct usubjid) as smaln
from firsthosp
where hostdt>trtsdt
group by trt01an, trt01a, section, sord, text
/*section 2*/
union
select trt01an, trt01a, 2 as section, 14 as sord, seqcat as text
length=200,count(distinct usubjid) as smaln
from hosp2
where seqcat>''
group by trt01an, trt01a, section, sord, text
/*section 3*/
union
select trt01an, trt01a, 3 as section, 15 as sord, durcat as text
length=200,count(distinct usubjid) as smaln
from durcat
where durcat>''
group by trt01an, trt01a, section, sord, text
/*section 4*/
union
select trt01an, trt01a, 4 as section, 16 as sord,
'Total days of hospitalization [1][2]' as text length=200,sum(eoh_los) as smaln
from totdayshosp
group by trt01an, trt01a, section, sord, text
union
select trt01an, trt01a, 4 as section, 17 as sord,
' During day 1 - day 90' as text length=200,sum(eoh_los) as smaln
from d190out1
group by trt01an, trt01a, section, sord, text
union
select trt01an, trt01a, 4 as section, 18 as sord,
' Subgroup excluding any stay began before day 1' as text
length=200,sum(eoh_los) as smaln
from exclude_beforeday1
group by trt01an, trt01a, section, sord, text
union
select trt01an, trt01a, 4 as section, 19 as sord,
' Subgroup excluding Azacitidine dosing' as text length=200,sum(eoh_los) as
smaln
from excludeazaout1
group by trt01an, trt01a, section, sord, text
/*section 5*/
union
select trt01an, trt01a, 5 as section, 20 as sord, 'Total days alive during day 1 -
day 90' as text length=200,sum(alive_stay) as smaln
from alivestay
where alive_stay ne . /*and durcatn in(2,3,4)*/
group by trt01an, trt01a, section, sord, text
union
select trt01an, trt01a, 5 as section, 20.5 as sord, 'Hospital days per days alive
during day 1 - day 90 (%) [1][2][3]'
as text length=200,per as smaln
from aliveprcnt
group by trt01an, trt01a, section, sord, text
/*section 6*/
union
select trt01an, trt01a, 6 as section, 21 as sord,' '||strip(daysdur) as text
length=200,count(distinct usubjid) as smaln
from hosp3
where daysdur>''
group by trt01an, trt01a, section, sord, text
quit;
data hosp33;
set hosp3;
if hoendt<hostdt then delete;
run;
proc sort data=hosp33;by trt01an trt01a;run;
proc means data=hosp33 noprint min max median std mean;
by trt01an trt01a;
var hosp_stay_cat;
data duration;
set duration;
section=7;sord=23;
run;
data tth2;
set tth_stat;
section=8;sord=25;
run;
data section78;
merge duration tth2 ;
by section sord;
run;
md1=(put(md, 10.1));
if missing(md) then md1=put('NE',4.);
run;
*transposing data;
proc transpose data=step1 out=t_step1(rename=(_name_=text)) prefix=TRT ;
by section sord;
id trt01an;
var mn1 md1 minmax;
run;
proc sort;by section sord text;run;
data allset1;
merge t_cnt t_step1;
by section sord text;
run;
****Creating the frame of texts*******;
data frame;
length text $200;
run;
data allset2;
merge allset1 frame;
by section sord text;
end;
data dummy;
length text $200 ;
*trt1=strip(trt1);
*trt2=strip(trt2);
data result_;
set result;
array nn trt:;
do over nn;
if NAME = 'perc' and nn = '' then nn = strip(put(0, 9. -r));;
end;
run;
DATA _NULL_;
CALL SYMPUT("FDATE",LEFT(PUT("&sysdate."d,YYMMDDN8.)));
RUN;
%xurtfsty();
%xurtfpt4(1, libref=tables);
data _null_;
length lstfootl1 lstfootr1 lstfootl2 lstfootr2 $ 200;
lstfootl1="Source: Listing 16.3.7.1";
lstfootr1 = "Data Cutoff Date: &dcutdt.";
lstfootl2="Program Name:
/&CLNT./&PROJ./&TASK./%sysget(TASKDIR)/programs/tables/&SYSPARM..sas";
lstfootr2="Run Date: &sysdate9.(&SYSTIME)";
underln = repeat('_',161);
call symput('lstfootl1',lstfootl1);
call symput('lstfootr1',lstfootr1);
call symput('lstfootl2',lstfootl2);
call symput('lstfootr2',lstfootr2);
call symput('underln',underln);
run;
proc report data = result_ headskip headline split='|' nowd ls=161 ps=&ps. missing
spacing=2;
column pg section sord text trt1 trt2;
run;
%xurtfpt4;
title;
footnote;