Data have; input id $ test$ visit result; 1 ALT 1 25 1 ALT 2 35 1 ALT 3 35 2 ALT 1 20 3 AST 1 20 3 AST 2 20; run; Data want; input id$ test$ visit result flg$; 1 ALT 1 25 . 1 ALT 2 35 . 1 ALT 3 35 Y 2 ALT 1 20 Y 3 AST 1 20 . 3 AST 2 20 Y; run;
data want;
set have;
by id;
if last.id then flg='Y'; else flg='.';
run;
If I may be so bold, setting FLG to 'Y' or '.' is not such a good idea; setting FLG to numeric 0 or 1 is not only easier to type, but has other benefits as well (such as computing proportions that are flagged can be done by computing a mean).
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.