Now, I would like to create three variables, time_1, time_2, time_3. These three time variables represent presence or absense (0/1) of a bank balance of >$0 for a particular bankID in the previous year, in two years previous, and three year previous.
Example 1. When SAS is evaluating year 2000, then it should create variables temp_1, temp_2, and temp_3 based on bank balances for the unique bankIDs during years 1999, 1998, and 1997. Since data for years 1997-1999 are missing, temp_1, temp_2, and temp_3 values for year 2000 should have missing values. In case of year 2001, data for years 1998 and 1999 are missing, so temp_2 and temp_3 values for year 2001 should be set to missing.
Example 2. For year 2003 and bankID 1, bank balance for year 2002 (temp_1) is 15, so temp_1 would be 1, however for 2000 (temp_3) the bank_balance is 0, so value of temp_3 would be 0.
Any suggestions regarding an appropriate SAS program to process this data will be highly appreciated. Thank you.
by bank_id year;
time_1 = not not lag1(cash_balance);
time_2 = not not lag2(cash_balance);
time_3 = not not lag3(cash_balance);
if first.bank_id then count = 0;
count + 1;
do _n_ = count to dim(time_);
time_[_n_] = .;