DATA Step, Macro, Functions and more

Removing duplicates problem

Accepted Solution Solved
Reply
Contributor
Posts: 60
Accepted Solution

Removing duplicates problem

I have a data set and it contains Claim sfx and amount , I need to remove the duplicates claim , but the problem here is there could be different sfx in the same claim , if its different for the same claim then I need to keep that claim

 

Claim     sfx          amount               

100         23           897        

100         23           897        

101         25           789        

101         89           463         Need to keep this Claim because of different sfx

102         56           789        

102         56           789         Need to delete this becase of same sfx


Accepted Solutions
Solution
‎06-22-2017 11:23 AM
Super User
Posts: 9,671

Re: Removing duplicates problem

data have;
input Claim     sfx          amount   ;
cards; 
100         23           897        
100         23           897        
101         25           789        
101         89           463     
102         56           789        
102         56           789
;
run;
proc sql;
create table want as
select *
 from have 
  group by claim
   having count(distinct sfx) ne 1;
quit;

View solution in original post


All Replies
Super User
Posts: 5,074

Re: Removing duplicates problem

SAS can do this fairly easily:

 

proc sort data=have nodupkey;

by claim sfx;

run;

 

However, you should also consider what is the right outcome when CLAIM is the same, SFX is the same, but AMOUNT changes.  perhaps you should go with:

 

proc sort data=have nodupkey;

by claim sfx amount;

run;

Solution
‎06-22-2017 11:23 AM
Super User
Posts: 9,671

Re: Removing duplicates problem

data have;
input Claim     sfx          amount   ;
cards; 
100         23           897        
100         23           897        
101         25           789        
101         89           463     
102         56           789        
102         56           789
;
run;
proc sql;
create table want as
select *
 from have 
  group by claim
   having count(distinct sfx) ne 1;
quit;
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 101 views
  • 0 likes
  • 3 in conversation