Is there a way to reset Lag fields to 0? I have the following code and want to reset the values in x1-11 when I move to a new by group based on level 1 and level 2. I tried resetting in a do loop but that is not working.....thanks for the help! DATA ADD_LAGS; SET WORK.SUMMARY_RET_DATA; BY level1 level2 YYYYMM SUM_OF_BILLINGS; *retain x1-x11 Rolling_12; if first.level1 then do; x1=0; x2=0; x3=0; x4=0; x5=0; x6=0; x7=0; x8=0; x9=0; x10=0; x11=0; end; x1 =lag1(sum_of_Billings); x2 =lag2(sum_of_Billings); x3 =lag3(sum_of_Billings); x4 =lag4(sum_of_Billings); x5 =lag5(sum_of_Billings); x6 =lag6(sum_of_Billings); x7 =lag7(sum_of_Billings); x8 =lag8(sum_of_Billings); x9 =lag9(sum_of_Billings); x10=lag10(sum_of_Billings); x11=lag11(sum_of_Billings); If _N_ = 1 then Rolling_12 = sum_of_Billings; Else if _N_ < 12 then Rolling_12 + sum_of_Billings; Else Rolling_12 = sum(sum_of_Billings,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11); run;
... View more