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

Hi Community,

 

I wanted your help in the following issue.

 


data dsn;
input ID $1. Seq $4. Group $5.;
cards;
1 01 BC
1 02 BC
2 00 LC
3 01 BC
3 02 LC
4 00 BC
5 01 BC
5 02 KC
5 03 BC
5 04 KC
;
run;

 

 

I want to delete all the ID's which have group other than BC. Not just the row but all the rows of that ID.

 

Thank you for your time and Help.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

There are a few possibilities  This one assumes your data is sorted as indicated in your sample data:

 

data want;

merge have have (where=(group ne "BC") in=delete_these);

by id;

if delete_these then delete;

run;

 

There will be a message about a many-to-many merge, but the result will still be correct.

View solution in original post

3 REPLIES 3
Astounding
PROC Star

There are a few possibilities  This one assumes your data is sorted as indicated in your sample data:

 

data want;

merge have have (where=(group ne "BC") in=delete_these);

by id;

if delete_these then delete;

run;

 

There will be a message about a many-to-many merge, but the result will still be correct.

novinosrin
Tourmaline | Level 20
data dsn;
input ID $1. Seq $4. Group $5.;
cards;
1 01 BC
1 02 BC
2 00 LC
3 01 BC
3 02 LC
4 00 BC
5 01 BC
5 02 KC
5 03 BC
5 04 KC
;
run;

proc sql;
create table want as
select *
from dsn
group by id
having max(upcase(Group) ne 'BC')=0
order by id, seq;
quit;
shasank
Quartz | Level 8
Thank you for your response and time. This worked too.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1436 views
  • 1 like
  • 3 in conversation