I think you can simply a great deal. You don't need to keep separate queues for 1-month lag, 2-month lag, etc. You really only need to keep a running total, adding the current record and subtracting the 12-month old record, as in:
data want;
set have;
rolling_12 + billings - coalesce(lag12(billings),0);
window_size=min(12,_n_);
run;
Since the first 12 observations have lag12(billings)= missing, I should not attempt to subtract those values, so instead I subtract
coalesce(lag12(billings),0)
COALESCE takes the left-most non-missing value from the list of argument, which means the zero for the first 12 obs.
... View more