BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Cruise
Ammonite | Level 13

Hi folks,

 

I have a data with missing and I'd like to flag those individuals with missing data across all the rows as shown in the snippet below. 

Any suggestions appreciated. Thanks in advance. 

DATA HAVE;
INPUT ID DIAGNOSIS FLAG;
CARDS;  
1 3  0 
1 1  0
1 99 0
1 99 0
1 99 0
1 99 0
1 1  0
1 99 0
1 3  0
1 99 0
2 99 1
2 99 1
2 99 1
2 99 1
2 99 1
;
PROC PRINT; RUN; 
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

DATA HAVE;
INPUT ID DIAGNOSIS;* FLAG;
CARDS;  
1 3  0 
1 1  0
1 99 0
1 99 0
1 99 0
1 99 0
1 1  0
1 99 0
1 3  0
1 99 0
2 99 1
2 99 1
2 99 1
2 99 1
2 99 1
;

proc sql;
create table want as
select *,sum(DIAGNOSIS=99)=n(id) as flag
from have 
group by id;
quit;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

So 99 is indicating 'missing' here?

Cruise
Ammonite | Level 13
YES
PeterClemmensen
Tourmaline | Level 20

You can do something like this

 

data have;
input id diagnosis;
cards;  
1 3 
1 1 
1 99
1 99
1 99
1 99
1 1 
1 99
1 3 
1 99
2 99
2 99
2 99
2 99
2 99
;

data want(drop=c);
   c=0;
   do _n_ = 1 by 1 until (last.id);
      set have;
      by id;
      if diagnosis=99 then c=c+1;
   end;

   do until (last.id);
      set have;
      by id;
      flag=ifn(c=_N_, 1, 0);
      output;
   end;

run;
novinosrin
Tourmaline | Level 20

DATA HAVE;
INPUT ID DIAGNOSIS;* FLAG;
CARDS;  
1 3  0 
1 1  0
1 99 0
1 99 0
1 99 0
1 99 0
1 1  0
1 99 0
1 3  0
1 99 0
2 99 1
2 99 1
2 99 1
2 99 1
2 99 1
;

proc sql;
create table want as
select *,sum(DIAGNOSIS=99)=n(id) as flag
from have 
group by id;
quit;
Cruise
Ammonite | Level 13

Thanks both of you. Excellent solutions. 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 848 views
  • 3 likes
  • 3 in conversation