Numbers are worth thousand words. Here is a very simple array approach. No need to use lag() function. I assumed your months are numbers like 1 , 2 , ... But it doesn't affect the array approach. The steps are: [1] Store the values of A into an array (K[]) which is indexed by MONTH. [2] Getting the lag1 for Month i is simply to get the value of A corresponding to (i-1)th month. [3] When A is missing, we use the lag value, compute Z and replace the missing value by Z in the array. data want;
array k[9] _temporary_;
do until(eof);
set have end = eof;
k[month] = a;
end;
month = 1;
a = k[1];
output;
do i = 2 to 9;
month = i;
if k[i] = . then do;
lag_a = k[i-1];
z = 2 * lag_a;
a = z;
k[i] = a;
end;
else do;
a = k[i];
lag_a = k[i - 1];
z = 2 * lag_a;
end;
output;
end;
drop i;
run; If you have any problem to handle the array because of then values of month, come back and tell how your real months are. It can be handled by the array. Hope this solution is acceptable to you.
... View more