Thank you to all the helpers, I think Peter's solution is the simplest perhaps. I have another problem is that not all the observations with non-missing fyear+1 and fyear+2. In order to mitigate this problem and to ensure all the gvkey with non-missing years, I perform the following: proc sql; create table a as select * from (select distinct FYEAR from SAMPLEDATA), (select distinct GVKEY from SAMPLEDATA) ; quit; data want; merge a SAMPLEDATA; by gvkey FYEAR; run; However, if I wish to exclude missing observations from a given year, how should I do that? For example, if I wish to compute the sum_txpd3 for a given gvkey for year 2013, I must have non-missing txpd for year 2011, 2012 and 2013. If the data for 2012 is missing, then the sum_txpd3 should be left as ".". With the code given by Peter, the the total of txpd for years 2011 to 2013 still will be calculated even if there is one missing txpd, lets say 2012. Thank you. Regards, MSPAK
... View more