Of course,
I would not miss such kind of question.
data have;
input id beginning_date :ddmmyy10. end_date :ddmmyy10. product $;
format beginning_date end_date ddmmyyp10.;
cards;
1 01.01.2016 31.01.2016 A
1 10.01.2016 29.01.2016 B
1 15.01.2016 31.01.2016 C
;
run;
data temp(index=(product xx=(id date)));
set have;
do date=beginning_date to end_date;
output;
end;
drop beginning_date end_date;
run;
proc sql;
create table x as
select distinct product from have;
quit;
data _null_;
set x end=last;
if _n_=1 then call execute('data all;merge ');
call execute('temp(where=(p_'||put(_n_,8.-l)||'="'||product||'")
rename=(product=p_'||put(_n_,8.-l)||'))');
if last then call execute(';by id date;length f $ 200;f=catx("+",of p_:); run;');
run;
data want;
set all;
by id f notsorted;
retain first;
if first.f then first=date;
if last.f then do;begin_date=first;end_date=date;output; end;
format date Begin_date end_date date9.;
drop date p_: first;
run;
... View more