Yeah you're welcome. Here's even another equivalent way that does not require a nested sub-expression. You can choose the most efficient one for your data set. By the way, did my solution of FIFO returns work for you? Please go to the question page and give some feedback about whether it works. Thanks. Bill proc sql; create table want_grouped2 as select distinct A.*, coalesce(SUM(B.FLAG),0) as number from have as A left join have as B on A.ID=B.ID and A.TIME-5<=B.TIME<=A.TIME-1 group by A.time order by A.ID, A.time; quit;
... View more