data A;
input ID Year Start End Type $;
cards;
1 2000 5000 5055 A
1 2000 5125 5365 A
1 2001 5366 5600 A
;
run;
data B;
input ID Year Start End Type $;
cards;
1 2000 5025 5100 B
1 2000 5200 5300 B
1 2001 5500 5800 B
;
run;
data tempA;
set a;
do date=start to end;
output;
end;
drop start end;
run;
data tempB;
set b;
do date=start to end;
output;
end;
drop start end;
run;
data temp;
merge tempA tempB(rename=(type=_type));
by id year date;
new_type=coalescec(_type,type);
run;
data temp;
set temp;
by id year new_type notsorted;
if first.new_type then group+1;
run;
data want;
set temp;
by group;
retain start;
if first.group then start=date;
if last.group then do;end=date;output;end;
drop date group type _type;
run;
... View more