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


I have a data like this.

ID Name Amount
1 Pink(1) $50-----This is Duplicate
1 Pink(2) $50-----This is Duplicate
2 Pink(1) $20
2 Pink(1) $25
3 Pink(1) $10
4 Pink(1) $15
5 Pink(1) $20----This is not duplicate
5 Pink(1) $20 ---This is not duplicate

I am trying to remove the duplicate (Id) 1 which have Pink 1 and 2 but with same amount $50.
Even though the ID 5 seems to be same , that not duplicate.

Pink have 2 categories 1 and 2. If 1 or 2 have same value then its duplciate.Name is a char variable.

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
input ID Name $ Amount $;
cards;
1 Pink(1) $50
1 Pink(2) $50
2 Pink(1) $20
2 Pink(1) $25
3 Pink(1) $10
4 Pink(1) $15
5 Pink(1) $20
5 Pink(1) $20
;
run;
proc sql;
create table a as
 select * 
  from have 
   group by id
    having count(distinct name) ne 1;

create table b as
 select * 
  from have 
   group by id
    having count(distinct name) eq 1;
quit;

data aa;
 set a;
 by id Amount;
 if first.Amount;
run;
data want;
 set aa b;
run;

View solution in original post

2 REPLIES 2
Reeza
Super User

Use SCAN to pull out that 'second' variable 1/2 that's combined with your name.

Then use PROC SORT to order the data.

 

You'll likely need a data step instead and use FIRST/LAST processing.

 

Post what you've tried if you're still having issues.

Ksharp
Super User
data have;
input ID Name $ Amount $;
cards;
1 Pink(1) $50
1 Pink(2) $50
2 Pink(1) $20
2 Pink(1) $25
3 Pink(1) $10
4 Pink(1) $15
5 Pink(1) $20
5 Pink(1) $20
;
run;
proc sql;
create table a as
 select * 
  from have 
   group by id
    having count(distinct name) ne 1;

create table b as
 select * 
  from have 
   group by id
    having count(distinct name) eq 1;
quit;

data aa;
 set a;
 by id Amount;
 if first.Amount;
run;
data want;
 set aa b;
run;

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
  • 2 replies
  • 1230 views
  • 1 like
  • 3 in conversation