Please show your current code with a simple lag1 with no 'skips'. This could be a case where you could use a conditional lag. So if X=. indicates the records that should be skipped, your lag might be:
if not missing(x) then lag_total=lag(total) ;
You will see plenty of tips where people say "never use lag conditionally," but I think this is a case where conditional lag will do what you want. The key point is that lag1() does not give you the value from the row immediately before, it gives you the value that was stored the last time lag1() was executed.
... View more