• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / SAS / nodup vs nodupkey PROC SORT Options in SAS

nodup vs nodupkey PROC SORT Options in SAS

September 23, 2022 Leave a Comment

When working with data, the ability to remove duplicates from your data can be very valuable.

PROC SORT gives many different options for you to use which can change the behavior of what PROC SORT does.

Two options which are useful in PROC SORT which allow you to remove duplicates are ‘nodup’ and ‘nodupkey’.

In this article, you will learn the difference between the ‘nodup’ and ‘nodupkey’ PROC SORT options.

The Difference Between nodupkey and nodup Options When Using PROC SORT in SAS

PROC SORT is most used to sort data in SAS, but you can also use PROC SORT to remove duplicates with different options.

Two options which are available for us to use which are very useful are ‘nodup’ and ‘nodupkey’.

‘nodup’ removes duplicate observations and looks at the entire observation instead of just specified columns, while the ‘nodupkey’ option to remove observations with duplicate BY values. In other words, you can remove duplicates by key variables.

‘nodup’ is different from ‘nodupkey’ as ‘nodupkey’ removes duplicates based on specific columns and ‘nodup’ doesn’t consider any specified columns.

Let’s take a look at an example.

Let’s say we have the following dataset. We can see that there are a few duplicate values in the data.

data example;
input a b;
datalines;
1 2
1 2
1 2
2 6
2 6
2 6
2 8
;
run;

Let’s take a look at the behavior when using the ‘nodup’ option.

data example;
input a b;
datalines;
1 2
1 2
1 2
2 6
2 6
2 6
2 8
;
run;

proc sort data=example nodup;
    by a;
run;

/* example After PROC SORT */
    a    b
    1    2
    2    6
    2    8

As you can see, the duplicates were removed. Now, let’s see what happens when we use ‘nodupkey’ now.

data example;
input a b;
datalines;
1 2
1 2
1 2
2 6
2 6
2 6
2 8
;
run;

proc sort data=example nodupkey;
    by a;
run;

/* example After PROC SORT */
    a    b
    1    2
    2    6

As you can see, there are more duplicates removed because we are only looking at the column ‘a’.

Hopefully this article has been useful for you to learn the difference between ‘nodup’ and ‘nodupkey’ in SAS when removing duplicates.

Other Articles You'll Also Like:

  • 1.  SAS scan Function – Return nth Word from Character String
  • 2.  SAS Remove Labels from Dataset with PROC DATASETS
  • 3.  SAS _n_ – How to Use the Automatic Variable _n_ in a Data Step
  • 4.  SAS tranwrd() Function – Replace Characters in Strings in SAS Data Step
  • 5.  SAS Less Than or Equal to with LE or <=
  • 6.  SAS Delete Dataset – Use PROC Datasets to Delete SAS Files
  • 7.  SAS sum() Function – Find Sum Across Columns in Data Step
  • 8.  SAS Dollar Format – Formatting Numbers as Dollars in SAS Dataset
  • 9.  Round Number to Nearest Integer in SAS
  • 10.  Get the Row Number in a SAS Data Step with _n_

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy