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

I am trying to get rid of duplicates in my data. I have decided a duplicate occurs if every column is the same except for code. I want to write a function to get rid of duplicates based on how I have defined them.

 

Below is an example of my current data set, and what I wish my desired data set to look like.

 

current data

IDCodeLodge dateapp dateChoiceCategoryRuleDollars
128011/04/2019 8:251/04/2019D1D005R015-26804
212521/04/2019 10:168/07/2019A1D005R015-5478
212531/04/2019 10:168/07/2019A1D005R015-5478
241341/04/2019 10:1710/06/2019A2R015253
241341/04/2019 10:1710/06/2019A2R015241

desired data

IDCodeLodge dateapp dateChoiceCategoryRuleDollars
128011/04/2019 8:251/04/2019D1D005R015-26804
212521/04/2019 10:168/07/2019A1D005R015-5478
241341/04/2019 10:1710/06/2019A2R015253
241341/04/2019 10:1710/06/2019A2R015241

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
japelin
Rhodochrosite | Level 12

try this code.

proc sort data=have out=want nodupkey;
  by ID Lodge_data--Dollars;
run;

View solution in original post

4 REPLIES 4
Patrick
Opal | Level 21

Use Proc Sort and sort by all variables that you want to look at (everything except code) and use keyword NODUPKEY.

japelin
Rhodochrosite | Level 12

try this code.

proc sort data=have out=want nodupkey;
  by ID Lodge_data--Dollars;
run;
Patrick
Opal | Level 21

@japelin Please note that what you propose will only work if the variables in the actual table are really in the order as shown in the reports.

japelin
Rhodochrosite | Level 12

@Patrick Thank you very much.
I wrote it in a simplified way because wanted to remove duplicates in variables other than Code, but the point is important.

 

 @sasprogramming Please make sure that the order of the variables in the dataset matches the order of the variables you have presented!

 

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