Hi Linlin, Art and Haikuo, Thank very much to everyone of you. All the 3 codes are producing the inteneded results given the sample data sets. Hi Linlin, Then I applied Linlin's code to my large dataset and it produced an unintended output. The reason is I did not cleverly reflect all "record possibilities" in my data set I posted. Now I included one such additional business reality I observed in my original data set (please see "red color highlighed" record in have_1 dataset below). One more thing that I have still not reflected in this small "posting data set" is this. All the bank_number s found in Have_1 data set are found in Have_2 dataset too. data Have_1; informat Current_date date9.; Input Current_date Account_number $12-14 Arrears_Band $ 17-23 balance bank_number; Format Current_date date9.; cards; 28FEB2010 111 NPNA 10 100 31MAR2010 111 Current 20 100 31MAY2010 111 30 - 60 30 100 28FEB2010 444 Current 40 900 31MAR2010 444 30 - 60 50 900 30APR2010 444 30 - 60 60 900 31MAY2010 444 Current 70 900 30APR2010 555 Current 80 700 31MAY2010 555 NPNA 90 700 31AUG2011 555 90 + 12 700 30SEP2011 555 NPNA 0 700 31MAY2010 666 Current 15 400 31AUG2011 666 90 + 20 400 30SEP2011 666 Current 30 400 30SEP2011 999 Current 30 300 /*I added this record*/ ; run; data Have_2; informat Post_date date9.; Input Post_date Account_number $12-14 Net_Write_off_total_USD bank_number; Format Post_date date9.; cards; 31AUG2010 111 50 100 31AUG2010 111 50 200 30SEP2011 555 77 700 30SEP2011 666 77 300 ; run; When Linlin's code is applied,it selects 17th record also highlighted in below output. This shouldn't have been slected.Why? In have_1 dataset there is no account called 666 in bank_number 300 although there is a bank_number called 300. I am sure Linlin will tweak her code in a few seconds and I will take hours/days to understand it. 1 28FEB2010 111 NPNA 10 100 2 31MAR2010 111 Current 20 100 3 31MAY2010 111 30 - 60 30 100 4 31AUG2010 111 writoff 50 100 5 28FEB2010 444 Current 40 900 6 31MAR2010 444 30 - 60 50 900 7 30APR2010 444 30 - 60 60 900 8 31MAY2010 444 Current 70 900 9 30APR2010 555 Current 80 700 10 31MAY2010 555 NPNA 90 700 11 31AUG2011 555 90 + 12 700 12 30SEP2011 555 NPNA 0 700 13 30SEP2011 555 writoff 77 700 14 31MAY2010 666 Current 15 400 15 31AUG2011 666 90 + 20 400 16 30SEP2011 666 Current 30 400 17 30SEP2011 666 writoff 77 300 18 30SEP2011 999 Current 30 300 Hi Art and Haikuo, When I apply both of your codes even for the newly-included business reality, both your code produce intended results (meaning the output table doesn't have 17th record highlightedin above table). Thanks again to all of you. Mirisage
... View more