Hi Hai.Kuo, I got it working using following code: data have; input id $ dt yymmdd10. status $; format dt yymmdd10.; cards; 1 20141203 D 1 20141210 D 1 20141210 A 1 20141210 S 1 20150110 A 1 20150118 S 2 20150104 A 2 20150115 D 2 20150118 S 2 20150118 D 2 20150118 A 3 20150210 S 3 20150213 D 3 20150223 D 3 20150223 S ; data have; set have; mnth = substr(put(dt,yymmddn8.),1,6); if status = 'A' then seq = 1; else if status = 'S' then seq = 2; else if status = 'D' then seq = 3; run; proc sort data = have; by id mnth descending seq; run; data want; set have; if last.mnth; by id mnth descending seq; keep id mnth status; run; Output was as follows: ID mnth Status 1 201412 A 1 201501 A 2 201501 A 3 201502 S
... View more