How to get these flags under the following scenarios:
Flag = "Y" if meet one of the following scenarios:
1. There is no AVALC = 'N' after the AVALC='Y' then flag should be the last non-missing record .
2. Subject ended with two consecutive missing ADY , then should flag the last AVALC = 'Y' prior to missed ADY.
4. Subject ended with one missing ADY and ADY is the last one, then should flag the last AVALC = 'Y' prior to missed ADY.
data have;
input usubjid $ ADY AVALC $;
datalines;
A 15 Y
A 36 Y
A 57 Y
A 63 Y
A 64 Y
A . N
B 15 Y
B 16 Y
B 17 Y
B . N
B . N
B . N
B 25 N
B . N
B 29 Y
B 30 Y
B 31 Y
B . N
c 17 Y
c 18 Y
c . N
c . N
D 11 Y
D . N
D 13 Y
D 14 Y
D 15 Y
E 1 N
E 2 N
E 3 N
E 4 Y
;
run;
Records: A 64 Y ; B 17 Y;c 18 Y;D 15 Y;E 4 Y are flagged. Thank you so much!
This sounds a lot like a homework assignment.
Even if that is not the case, let us know how you think about this task, and what you have tried. Help us to help you master the problem.
I try to use the find ti position different AVALC based on the rules, but looks like not a good idea
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.