Hello,
I have a account list with value at different time from T1 to T6. I am trying to flag the record when any of 3 consecutive time records have value under 5:
I know I can check if (T1<5 and T2<5 and T3<5 ) or (T2<5 and T3<5 and T4<5) or .... under four combinations
I wonder whether there is any smart and advance way to code this?
Thank you,
Acct | T1 | T2 | T3 | T4 | T5 | T6 |
a | 4 | 4 | 4 | 3 | 3 | 3 |
b | 10 | 6 | 4 | 4 | 4 | 8 |
c | 9 | 9 | 9 | 2 | 2 | 1 |
d | 8 | 8 | 8 | 7 | 6 | 5 |
e | 4 | 2 | 9 | 3 | 3 | 2 |
If you contemplate looking for series of numbers substantially longer than 3 time points, you might want to forego the syntax of
x{i}<5 and x{i+1}<5 and ...
and try using the MAX function:
data want;
set have;
array t t1-t6;
flag=0;
do i=1 to dim(t)-2 until (flag=1);
flag=(max(t{i},t{i+1},t{i+2})<5);
end;
drop i;
run;
Also the "until (flag=1)" expression stops the looping if a qualifying series if found in an early iteration.
UNTESTED CODE
data want;
set have;
array t t1-t6;
flag=0;
do i=1 to dim(t)-2;
if t(i)<5 and t(i+1)<5 and t(i+2)<5 then flag=1;
end;
drop i;
run;
If you want tested code, do not provide data as screen captures. Provide data as working SAS data step code (instructions), or by typing it in yourself.
If you contemplate looking for series of numbers substantially longer than 3 time points, you might want to forego the syntax of
x{i}<5 and x{i+1}<5 and ...
and try using the MAX function:
data want;
set have;
array t t1-t6;
flag=0;
do i=1 to dim(t)-2 until (flag=1);
flag=(max(t{i},t{i+1},t{i+2})<5);
end;
drop i;
run;
Also the "until (flag=1)" expression stops the looping if a qualifying series if found in an early iteration.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.