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!

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 770 views
  • 1 like
  • 3 in conversation