Hi Yanagi, You can use Lag function to get the last period in the curret row, and with by statments to get the the new column count for your needs. data temp; input ID Year Quarter ; date=mdy(quarter*3,01,year); format date ddmmyy10.; cards; 1 2000 1 1 2000 2 1 2000 3 1 2000 4 1 2001 1 1 2004 2 2 1999 4 2 2000 1 ; run; proc sort data=temp; by id date; run; data temp2; set temp end=eof; by id date; date_prev=lag(date); if first.id then do; count=1; date_prev=date; end; else do; if mdy(month(intnx('quarter',date_prev,1,'end')),01,year(intnx('quarter',date_prev,1,'end')))=date then count+1; else count=1; end; format date_prev ddmmyy10.; run;
... View more