I don't understand why you have a Y for ID 2. Here's my best guess for what you're trying to do: proc sql; create table want as select t1.id, t1.date, t1.spend, sum(t2.spend) as Rolling_Spend, case when sum(t2.spend) >=50 then 'Y' end as Flag from have t1 left join have t2 on t1.id=t2.id and intck('month',t2.date,t1.date) between 0 and 2 group by t1.id, t1.date, t1.spend order by t1.id, t1.date; quit; id date spend Rolling_Spend Flag 1 01Jan2010 20 20 1 01Feb2010 10 30 1 01Mar2010 0 30 1 01Apr2010 10 20 1 01May2010 40 50 Y 2 01Mar2009 20 20 2 01Apr2009 10 30 2 01May2009 10 40 2 01Jun2009 10 30 2 01Jul2009 5 25 2 01Aug2009 15 30
... View more