BookmarkSubscribeRSS Feed
thanikondharish
Fluorite | Level 6

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

.

1 REPLY 1
Astounding
PROC Star

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;

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 827 views
  • 2 likes
  • 2 in conversation