I have 3 columns i.e id, date and status and Status has 3 categories (ND, prob and Default). I wanted to make desired_col mentioned on below data sample and this column will make based on below conditions. When default occurs it will check below 6 rows and if it finds ND then it will count how many rows in between default and ND. In below example the first default occurs in feb01 and now it will check below 6 rows and it finds after 4 rows the status becomes ND then in desired columns it gives 4 and so on. Could someone please help this query in SAS. Id date status desired_col A jan01 ND . A feb01 Default 4 A mar01 Prob. 3 A apr01 prob. 2 A may01 prob. 1 A jun01 ND. . A jul01 ND. . A aug01 ND. . A sep01 Default. 5 A oct01 Prob. 4 A nov01 prob. 3 A dec01 prob. 2 A jan02 prob. 1 A jan02 ND. .
... View more