I have a data set containing an unbalanced panel of observations, where I want to forward and backward fill missing and/or \"wrong\" observations of ticker with the latest non-m
You can do this several ways, but proc sql
with some nested sub-queries is one solution.
(Read it from inside out, #1 then 2 then 3. You could build each subquery into a dataset first if it helps)
proc sql ; create table want as /* #3 - match last ticker on id */ select a.id, a.time, a.ticker_have, b.ticker_want from have a left join /* #2 - id and last ticker */ (select x.id, x.ticker_have as ticker_want from have x inner join /* #1 - max time with a ticker per id */ (select id, max(time) as mt from have where not missing(ticker_have) group by id) as y on x.id = y.id and x.time = y.mt) as b on a.id = b.id ; quit ;