BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ndamo
Obsidian | Level 7

Dear community , 

I need your help. I have a dataset like this 

ID   indication 

1        A

1        B

1        A

1        A

2        A

2        A

2        A

2        A

I would like to remove ID were indication = B  like the output below:

2        A

2        A

2        A

2        A

 

Thank you 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Here is how I interpret your needs: 

 

You want to remove the entire ID group if one or more observations within that group has indication = 'B'. Correct?

 

That is exactly what my code does, both in the previous example and in this one 🙂

 

See the posted results as well.

 

data have;
input ID Indication $;
datalines;
1 A
1 B
1 A
1 B
2 C
2 C
2 C
2 C
3 A
3 B
3 C
3 D
4 A
4 C
4 D
4 E
;

proc sql;
   create table want as
   select * from have
   group by ID
   having(sum(indication = 'B') = 0)
   ;
quit;

 

Result:

 

ID  Indication
2   C
2   C
2   C
2   C
4   D
4   C
4   A
4   E

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20
data have;
input ID indication $;
datalines;
1 A
1 B
1 A
1 A
2 A
2 A
2 A
2 A
;

proc sql;
   create table want as
   select * from have
   group by ID
   having(sum(indication = 'B') = 0)
   ;
quit;

 

Result:

 

ID  indication
2   A
2   A
2   A
2   A

 

ndamo
Obsidian | Level 7

@PeterClemmensen 

Thank you but it did not work . Indeed my column Indication have the value A, B ,C, D , E .

The program you proposed removed all observation even if ID not equal to B.

For exemple here , the ID 1 and 3 should be deleted and keep ID 2 and 4.

ID Indication
1 A
1 B
1 A
1 B
2 C
2 C
2 C
2 C
3 A
3 B
3 C
3 D
4 A
4 C
4 D
4 E

 

PeterClemmensen
Tourmaline | Level 20

Here is how I interpret your needs: 

 

You want to remove the entire ID group if one or more observations within that group has indication = 'B'. Correct?

 

That is exactly what my code does, both in the previous example and in this one 🙂

 

See the posted results as well.

 

data have;
input ID Indication $;
datalines;
1 A
1 B
1 A
1 B
2 C
2 C
2 C
2 C
3 A
3 B
3 C
3 D
4 A
4 C
4 D
4 E
;

proc sql;
   create table want as
   select * from have
   group by ID
   having(sum(indication = 'B') = 0)
   ;
quit;

 

Result:

 

ID  Indication
2   C
2   C
2   C
2   C
4   D
4   C
4   A
4   E
ndamo
Obsidian | Level 7

@PeterClemmensen 

It works. Thank you so much !😊

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 4 replies
  • 727 views
  • 1 like
  • 2 in conversation