Hi Thanks for the reply. It is great to see that the default_date and write_off_date could be figured out for each acct_id through this code. Please note that my query is a bit different. 1) For each observation date corresponding to a given acct_id (consider this as first date of observation and then look forward into next 12 months data), I am expected to check in the next 12 months including the given observation month for BQR , if it gets a value 9 then declare that acct_id at the given date to have a default_flag = 1 else 0 against that record 2) As soon as an acct_id gets a default_flag = 1, I am expected to check further if in the next 60 months, BQR gets a value "W". If it gets a value "W", then I have to declare that acct_id at that given month to have write_off_flag = 1 else 0 3) I am also expected to create forward looking variables BQR_1 to BQR_12 and populate values from the variable BQR for the next 12 months I have tried to create a macro, however there is an issue. %macro zest(); Data answers; Set credit_data; By acct_id; Array _bqr(*) $ BQR1-BQR12; If first.acct_id then count=1; Else count + 1; %do i = 1 %to 12 ; if eof&i. = 0 then set credit_data (firstobs=&i. keep=BQR rename=(BQR=BQR&i.)) end=eof&i. ; if last.acct_id then BQR&i. = ""; %end ; write_off_flag=whichc('W', of _bqr(*)); default_flag=whichc('9', of _bqr(*)); count_max = max(count); Run ; %mend; %zest Whereever the difference between the date of observance and the last date for each acct_id is less than 12 months, the code is trying to overstep and evaluate the data from the next acct_id. I want this code to be suitably modified such that forward looking variables BQR1-BQR12 is correctly populated. To further clarify, if the difference between the date of observance (nth record) & last date of acct_id is less than 12, say 11 then in this case BQR12 should be populated as BQR12 = . against nth record. Hope my query is clear. If you run the above macro on the dataset SAS code given in the chain message, and check for the dataset named "answers" and observe BQR1-BQR12 aginst each nth record in the dataset, you will get to know what is exactly happening.
... View more