A little announcement. A lot to explore.

Happy learning!

Explore lessons, including SAS & R programs and practice data.

Search lessons

Type at least 3 characters to see matching lessons.

Open SAS ↗Open R ↗
← SASnRHandling duplicates

Introduction

  • Duplicate rows come up in almost every real dataset — a subject entered twice, a lab value repeated across two sources, a merge that accidentally widened the data.
  • Two common asks: keep one row per key combination (nodupkey in SAS), or remove rows that are exact copies across every column (nodup / noduprec in SAS).
  • In SAS, proc sort nodupkey keeps one row per BY-group; proc sort noduprec drops full-row duplicates when paired with by _all_.
  • Tidyverse: distinct() for full-row deduplication; group_by() %>% slice(1) for one row per key combination.
  • Base R: !duplicated(df) for full rows; !duplicated(df[c("k1","k2")]) for a key-based version after sorting.
  • This lesson works two small AE datasets — one where duplication is key-based and one where full rows repeat — so we can see both patterns side by side.

Handling duplicates