data ex ;
input id $ visit $ result ;
cards ;
101 visit1 22
101 visit2 45
101 visit3 33
102 visit1 22
102 visit2 45
102 visit3 .
103 visit1 22
103 visit2 .
103 visit3 .
104 visit1 22
104 visit2 .
104 visit3 .
;
if visit2 missing and visit3 also missing the results column then assign 'y' in new variable where visit3 like see below dataset
new_flag | id | visit | result |
| 101 | visit1 | 22 |
| 101 | visit2 | 45 |
| 101 | visit3 | 33 |
| 102 | visit1 | 22 |
| 102 | visit2 | 45 |
| 102 | visit3 | . |
| 103 | visit1 | 22 |
| 103 | visit2 | . |
y | 103 | visit3 | . |
| 104 | visit1 | 22 |
| 104 | visit2 | . |
y | 104 | visit3 | . |
Hmmmm ...
It looks like a lot of people won't even respond to your questions. I understand the reasons why, but will respond to this one because the question is a reasonable one where it would be difficult to get the answer just by reading the documentation.
Try it this way:
data want;
set have;
by id;
if first.id then missing_visit_counter = 0;
if result = . then do;
if visit in ('visit2', 'visit3') then missing_visit_counter + 1;
if missing_visit_counter = 2 and visit='visit3' then result='y';
end;
drop missing_visit_counter;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.