Hi @Shamz and welcome to the SAS Support Communities!
Your sample data suggest that the values of DELINQUENCY_BUCKET within an acct_number BY group (which is not shown, though) are decreasing, except for one (or more?) observation. What should happen if DELINQUENCY_BUCKET has a second (third, ...) increase, e.g., to 72 after the last record shown in your screenshot?
If d_DELQ_BUCKET2 is to ignore these later increases (analogous to d_DELQ_BUCKET), I would suggest something like this:
data a(drop=_flag);
set b;
by acct_number;
if first.acct_number then do;
d_DELQ_BUCKET = DELINQUENCY_BUCKET;
d_DELQ_BUCKET2 = DELINQUENCY_BUCKET;
_flag+1;
end;
else do;
d_DELQ_BUCKET+(-1);
if DELINQUENCY_BUCKET>d_DELQ_BUCKET & _flag then do;
d_DELQ_BUCKET2 = DELINQUENCY_BUCKET;
_flag=0;
end;
else d_DELQ_BUCKET2+(-1);
end;
run;
However, if d_DELQ_BUCKET2 is to be "reset" also in the event of second, third, ... increases or if no such cases can occur anyway, I'd suggest:
data a;
set b;
by acct_number;
if first.acct_number then do;
d_DELQ_BUCKET = DELINQUENCY_BUCKET;
d_DELQ_BUCKET2 = DELINQUENCY_BUCKET;
end;
else do;
d_DELQ_BUCKET+(-1);
if DELINQUENCY_BUCKET>d_DELQ_BUCKET2 then d_DELQ_BUCKET2 = DELINQUENCY_BUCKET;
else d_DELQ_BUCKET2+(-1);
end;
run;
Why are you doing that MAX calculation, when you want a strictly decreasing sequence?
Please post example data in usable form, as a data step with datalines, and use the "little running man" button to post the code. One can't develop and test code against pictures. And post an example for the expected output from that example data.
Hi @Shamz and welcome to the SAS Support Communities!
Your sample data suggest that the values of DELINQUENCY_BUCKET within an acct_number BY group (which is not shown, though) are decreasing, except for one (or more?) observation. What should happen if DELINQUENCY_BUCKET has a second (third, ...) increase, e.g., to 72 after the last record shown in your screenshot?
If d_DELQ_BUCKET2 is to ignore these later increases (analogous to d_DELQ_BUCKET), I would suggest something like this:
data a(drop=_flag);
set b;
by acct_number;
if first.acct_number then do;
d_DELQ_BUCKET = DELINQUENCY_BUCKET;
d_DELQ_BUCKET2 = DELINQUENCY_BUCKET;
_flag+1;
end;
else do;
d_DELQ_BUCKET+(-1);
if DELINQUENCY_BUCKET>d_DELQ_BUCKET & _flag then do;
d_DELQ_BUCKET2 = DELINQUENCY_BUCKET;
_flag=0;
end;
else d_DELQ_BUCKET2+(-1);
end;
run;
However, if d_DELQ_BUCKET2 is to be "reset" also in the event of second, third, ... increases or if no such cases can occur anyway, I'd suggest:
data a;
set b;
by acct_number;
if first.acct_number then do;
d_DELQ_BUCKET = DELINQUENCY_BUCKET;
d_DELQ_BUCKET2 = DELINQUENCY_BUCKET;
end;
else do;
d_DELQ_BUCKET+(-1);
if DELINQUENCY_BUCKET>d_DELQ_BUCKET2 then d_DELQ_BUCKET2 = DELINQUENCY_BUCKET;
else d_DELQ_BUCKET2+(-1);
end;
run;
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.