SAS Enterprise Guide

Desktop productivity for business analysts and programmers
BookmarkSubscribeRSS Feed
WorkUser
Obsidian | Level 7

Is there a way to remove duplicates in Query Builder? I usually check the “Select distinct rows only” box and it fixes the problem but in this case there are fields that don’t match so it will be included in the dataset. Can I remove duplicates by just a specific field rather than an entire row using the query builder?

Thanks

2 REPLIES 2
ballardw
Super User

If there are other variables that you need how do you identify which values of the other variables that you want?

 

jimbarbour
Meteorite | Level 14

@WorkUser wrote:

Can I remove duplicates by just a specific field rather than an entire row using the query builder?

Thanks


Not that I know of.  Generally that's not how SQL works.

 

However, you can use Proc Sort with a NODUPKEY option.

 

 

PROC  SORT  DATA=Have  NODUPKEY;
    BY  ID, Date;
RUN;

In the above example, only duplicates on both ID and Date will be eliminated.  If other columns in the dataset "Have" do not match, SAS will still drop a row if ID and Date match.  However, be aware, that SAS will just take the first one that it encounters.  If you have something like:
123 18AUG2021 Purchase

123 18AUG2021 Return

123 18AUG2021 Purchase

Only the first "Purchase" record would be retained. 

 

Jim

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 3845 views
  • 2 likes
  • 3 in conversation