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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.