Perhaps a little simpler:
data want;
set have;
by ID;
if first.ID then output_flag = 'N';
if (balance < 0 then output_flag = 'Y';
retain output_flag;
if output_flag = 'Y' and balance >= 0;
run;
However, there are always cases to consider:
Could there be missing values for BALANCE?
For the same ID, could there be a group of negative values, followed by a group of positive values, followed by another group of negative values? (What should happen then?)
So simple might be good, but it depends on some of the details involved in getting the intended result.
... View more