Nice answer, I was working on something very similar (using PROC SUMMARY with COMPLETETYPES). The bit I was struggling with to code relatively simply was missing imputation and coping with both lag and lead values (the lag part is easy). The only problem I can see with your solution is if there is only a value for 2003 in the example data (i.e. 2001 and 2002 are missing). Using firstobs=2 will still return a missing value here. Ideally you would want to read sequential records until a value is encountered, then return that. The nature of the data means that it is not possible to go to the next BY group before a non-missing value occurs, so that isn't a worry.
... View more