You essentially are asking how to do a reverse Last Observation Carried Forward (LOCF) operation. The simplest way to do LOCF is to take advantage of the UPDATE statement in a DATA step.
data locf ;
update have(obs=0) have ;
by id;
output;
run;
Do do the reverse just order the observations backwards. Your sample data does have a sort key so perhaps you can just make one.
data reverse;
set have;
row+1;
run;
proc sort data=reverse ;
by id descending row;
run;
data locb ;
update reverse(obs=0) reverse ;
by id;
output;
run;
But in addition to the reverse aspect you also added that you want to treat zeros as missing.
Why do you want to treat zero as missing?
If you do want to treat zero as missing then you could set them to missing in the step that is adding the ROW number variable.
data reverse;
set have;
row+1;
array varlist var1-var2;
do over varlist;
if varlist=0 then varlist=.;
end;
run;
... View more