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;