%let period= DAY;
data have; format entry_date discharge_date yymmdd10.;
informat entry_date discharge_date yymmdd10.;
length period $10.;
input @5 id @7 entry_date @19 discharge_date @30 note :$32 ;
if "&period."="YEAR" then do;
start = year(entry_date);
end = year(discharge_date);
do _period = start to end;
period=put(_period,z4.);
put _all_;
output;
end;
end;
else if "&period."="MONTH" then do;
start = entry_date;
end = discharge_date;
do _period = start to end ;
period=put(_period,yymm10.);
put _all_;
output;
_period = intnx('month',_period,1,'beg');
end;
end;
else if "&period."="DAY" then do;
start = entry_date;
end = discharge_date;
do _period = start to end ;
period=put(_period,Juldate7.);
output;
end;
end;
datalines;
1 2017-05-11 2018-08-25 Active 2017,2018
2 2017-04-01 2017-08-02 Active 2017
3 2018-05-11 2018-07-20 Active 2018
4 2019-01-05 2019-04-29 Active 2018, 2019
5 2020-05-11 2020-05-20 Active 2020
6 2020-04-05 2020-06-02 Active 2020
;;;
run;
proc means data=have nway missing noprint;
class period;
var ID;
output out= want count=;
run;
... View more