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. 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 1557 views
  • 3 likes
  • 3 in conversation