Maybe this: *Get the first and last date for each group;
proc sql noprint;
create table have_2 as
select *, min(DateCharacter) as period_start, max(DateCharacter) as period_end
from have
group by ID
order by ID, DateCharacter;
quit;
data want;
set have_2;
retain period;
by id;
*Fix the string dates to be SAS dates.;
_d=cats(DateCharacter,"01");
_d_start=input(cats(period_start,"01"),yymmdd10.);
_d_end=input(cats(period_end,"01"),yymmdd10.);
d=input(_d,yymmdd10.);
*Count the number of periods for this ID.;
if first.id then period = 1;
else period = period + 1;
*Fix the table name by concatination.;
table_name = cats(put(_d_start,date9.),"_",put(_d_end,date9.));
format d yymmdd10.;
*Get rid of temporary variables;
drop _d: period_start period_end;
run; BTW, it is a bit confusing that you have to look at two messages to try to figure out what you want. Better to rewrite it to one instead. 🙂
... View more