This is a good task for taking advantage of multiple datasets in a SET statememt. The SET statement below will insure that all the negative values greater/equal to -1000 will precede all values< -1000, so a test of value at last.id is sufficient: data want; retain negcount 0; set have (where=(-1000<=value<0)) have (where=(value<-1000)); by ID; if first.id then negcount=0; if value>= -1000 then negcount+1; if last.id & value>=-1000; run;
... View more