Updated:
data have;
infile datalines dlm=',' dsd truncover;
input ID Date:anydtdte. Returns Delisting_return month newmonth year;
format date date9.;
datalines;
1,1967-10-28,1.025,,10,07,1967
1,1967-11-28,1.026,,11,08,1967
1,1967-12-28,1.027,,12,09,1967
1,1968-01-28,1.01,,1,10,1968
1,1968-02-28,1.04,,2,11,1968
1,1968-03-28,1.001,,3,12,1968
1,1968-04-28,1.005,,4,01,1968
1,1968-05-28,1.02,,5,02,1968
1,1968-06-28,1.02,,6,03,1968
1,1968-07-28,1.06,,7,04,1968
1,1968-08-28,1.06,,8,05,1968
1,1968-09-28,1.0014,1.0014,9,06,1968
;
run;
data want (drop=i fst_date fst_newmonth);
set have;
by id;
retain fst_date fst_newmonth;
if last.id and month(date) ne 12 then do;
fst_date=date;
fst_newmonth=newmonth;
do i=0 to 12-newmonth;
date=intnx('month',fst_date,i);
if i > 0 then returns=.;
month=month(date);
year=year(date);
delisting_return=.;
newmonth=fst_newmonth+i;
output;
end;
end;
else output;
run;
... View more