• 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 / Identifying Duplicates in SAS with PROC SORT dupout Option

Identifying Duplicates in SAS with PROC SORT dupout Option

September 23, 2022 Leave a Comment

To identify duplicates in SAS, you can use PROC SORT and use the dupout option. ‘dupout’ will create a new dataset and keep just the duplicate observations of the original dataset.

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 dupout=dups noduprecs;
    by a;
run;

/* dups Dataset */
    a    b
    1    2
    1    2
    2    6
    2    6

You can also use the ‘nodupkey’ option to identify duplicates based on specific columns.

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 dupout=dups nodupkey;
    by a;
run;

/* dups Dataset */
    a    b
    1    2
    1    2
    2    6
    2    6
    2    8

When working with data, the ability to identify duplicates in your data can be very valuable.

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

When using PROC SORT in SAS, you can use the ‘dupout’ option to output duplicate observations. You can specify ‘nodupkey’ or ‘noduprecs’ as well to specify if the duplicates should be identified with BY values or for the entire observation.

Below is a simple example showing you how to identify duplicate observations with ‘dupout’ and ‘noduprecs’ in SAS with PROC SORT.

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 dupout=dups noduprecs;
    by a;
run;

/* dups Dataset */
    a    b
    1    2
    1    2
    2    6
    2    6

This is the opposite of if you used ‘nodup’ with PROC SORT.

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

You can also identify duplicate observations by BY values with the ‘nodupkey’ option. Below shows you how to identify duplicates with ‘nodupkey’ and ‘dupout’.

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 dupout=dups nodupkey;
    by a;
run;

/* dups Dataset */
    a    b
    1    2
    1    2
    2    6
    2    6
    2    8

This is the opposite of if you used ‘nodupkey’ with PROC SORT.

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

Hopefully this article has been useful for you to learn how to identify duplicates in SAS with PROC SORT.

Other Articles You'll Also Like:

  • 1.  SAS trim – Remove All Trailing Blanks from String Variable in Data Step
  • 2.  Get Last Observation of SAS Dataset with end=
  • 3.  SAS %eval() Function – Evaluate Expressions in SAS Macro
  • 4.  Set Multiple Datasets in SAS Data Step
  • 5.  SAS year function – Get Year from Date Variable
  • 6.  SAS Percent Format – Formatting Number as Percent in SAS Dataset
  • 7.  countw SAS – Count Number of Words in a String
  • 8.  SAS weekday function – Get Day of Week from Date Variable
  • 9.  SAS mean() Function – Find Average Across Columns in Data Step
  • 10.  SAS yymmdd10. Date Format

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