Hi ,
I have a span file and want to create month array in which each month counts the number of days a client stayed in hospital.
Thanks in advance !
Here is the sample file:
data myfile1;
input clientID $ (startDt EndDt)(:date9.);
format startDt EndDt date9.;
cards;
1111 03Oct2011 21Nov2011
1111 10Dec2011 11Jan2012
2222 15Jan2012 21MAR2012
2222 03May2012 24Jun2012
3333 03Nov2011 21Dec2011
;
run;
I want the outcome file like this: DayCount1 represents the earliest month in the StartDt, and DayCount9 represents the last month of
the EndDt.
%let FirstMo= %sysfunc(intck(month,"01Sep2011"d,"01Oct2011"d)); %let LastMo= %sysfunc(intck(month,"01Oct2011"d,"01Jul2012"d));
%put &FirstMo; %put &LastMo;
clientID
DayCount1
DayCount2
DayCount3
DayCount4
DayCount5
DayCount6
DayCount7
DayCount8
DayCount9
1111
28
21
21
11
0
0
0
0
0
2222
0
0
0
16
29
21
0
28
24
3333
0
27
21
0
0
0
0
0
0
The follow code create indicator array, but I need array that count # of days in each month clients stayed .
data myfile2;
set myfile1;
by clientID;
Adm_Mo= intck('month',"01Oct2011"d,startDt)+1;
Rel_Mo= intck('month',"01Oct2011"d,EndDt)+1;
retain flg&FirstMo. - flg&LastMo.;
array flg[&FirstMo.:&LastMo.] flg&FirstMo. - flg&LastMo.;
if first.clientID then do i = &FirstMo. to &LastMo.;
flg[i] = 0;
end;
do i = &FirstMo. to &LastMo.;
if i GE Adm_Mo and i LE Rel_Mo then flg[i] = 1;
end;
if last.clientID then output;
keep clientID flg&FirstMo. - flg&LastMo.;
run;
... View more