Tss, tss... and what both solutions where missing so far is what I included now in the end of the code.
Not very elegant - but it should work.
data input;
input year bank_ID cash_balance;
datalines;
2000 1 0
2000 2 0
2000 3 0
2000 4 0
2001 1 10
2001 2 20
2001 3 0
2001 4 5
2002 1 15
2002 2 22
2002 3 5
2002 4 7
2003 1 0
2003 2 0
2003 3 0
2003 4 0
2004 1 10
2004 2 20
2004 3 0
2004 4 5
2005 1 15
2005 2 22
2005 3 5
2005 4 7
;
run;
proc sort data=input;
by bank_id year;
run;
proc format;
value bool
>0 =1
;
run;
data lag;
set input;
by bank_id year;
time_1 = input(put(lag1(cash_balance),bool.),8.);
time_2 = input(put(lag2(cash_balance),bool.),8.);
time_3 = input(put(lag3(cash_balance),bool.),8.);
if bank_id ne lag1(bank_id) then time_1=.;
if bank_id ne lag2(bank_id) then time_2=.;
if bank_id ne lag3(bank_id) then time_3=.;
run;
Message was edited by: Patrick
... View more