The solution suggested by @FreelanceReinh looks good, but it can be made a little simpler and safer: data want;
set have;
if edate>. then do p=max(_n_-5,1) to min(_n_+5,nobs);
set have point=p nobs=nobs;
output;
end;
run; - using MAX and MIN functions is the easy way to make sure that you do not try to read non-existing observations. One word of warning: if your table contains deleted observations (e.g. because they have been edited with FSEDIT, or somebody used an SQL DELETE FROM statement on it), this will not work correctly. In that case you should copy your input to a temporary table first, like data Work.temp;
set mylib.have;
run; so that the table can be accessed with POINT= without problems. One question: If you have two valid Edates within 10 rows from each other, do you then want some of the observations output twice? If not, you may want to do something like this: data want;
set have;
if edate>. then do p=max(_n_-5,1,p+1) to min(_n_+5,nobs);
set have point=p nobs=nobs;
output;
end;
run; so that the same observation is not output twice. The point variable (P) is automatically initialized to 0 and retained.
... View more