BookmarkSubscribeRSS Feed
thanikondharish
Calcite | Level 5

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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