Hi @abdulla ,
Please respond to each point and number your three responses accordingly:
1) I understand the value in datadate should be one more year than the last datadate; it does not need any other column. Please let me know if this is correct, if not then please explain.
2) You are showing dots ('.') in your input data and output data, is that really what your input data is like (with dots, e.g. ".....") and is that really what you want your output data to look like (with dots, e.g. ".20070131..")?
3) I removed the dots and used the data in the following code and got the results shown further below. Please copy and paste the below code and run it in SAS. Check the "have" data set to confirm it looks correct or not. If "have" is correct, then let us know if the results are what you want and share your results - all rows, including headers.
data have;
infile datalines truncover;
input
gvkey : $char4.
fyear : $char4.
datadate : $char8.
;
datalines;
1001 2007 20071231
1001 2008
1001 2009 20091231
1002 2005 20060131
1002 2006
1002 2007 20080131
;
data want(drop = previous_datadate);
set have;
length previous_datadate $ 8;
retain previous_datadate;
if missing(datadate) then
datadate = cats(input(substr(previous_datadate,1,4),8.) + 1, substr(previous_datadate,5));
previous_datadate = datadate;
run;
proc print data = want;
run;
Results:
Obs gvkey fyear datadate
1 1001 2007 20071231
2 1001 2008 20081231
3 1001 2009 20091231
4 1002 2005 20060131
5 1002 2006 20070131
6 1002 2007 20080131
Kind regards,
Amir.
... View more