Business records and interpretation

Base SAS 9.3; note read 2026

SAS: Duplicate Keys and Whole Rows

Use a five-row example to distinguish repeated keys, identical observations and adjacent-output comparisons, with explicit ordering assumptions and worked results.

Original three-panel diagram comparing selected historical records and a labelled learning task
2 / 4 / 3
Invented output counts
5
Invented input rows

The short answer

Removing duplicates is incomplete as an instruction until the fields defining equality are specified. The selected technical note and manual distinguish two operations that can legitimately return different row counts.

The records answer different questions

Keep the measures separate

The question changes when the object, unit or reporting period changes.

Original comparison of the selected records.
Record or measureWhat it establishesWhat it does not establish
Duplicate keyEquality on selected ID fields.Equality on every measurement.
Adjacent full-row comparisonEquality against the preceding output row.An all-pairs duplicate search.
Distinct complete rowsEquality on every supplied field.One row per ID regardless of other fields.

Chronology

A timeline of the turning points

  1. State the sequence

    Ordering assumptions are part of the task.

  2. State the equality rule

    The retained rows depend on the chosen fields.

Equality depends on the selected fields

The Base SAS 9.3 manual says NODUPKEY removes observations sharing BY-variable values. EQUALS preserves relative input order for equal sort keys; NOEQUALS need not preserve that order.

A record with the same customer identifier but a different measurement is a duplicate key without necessarily being a duplicate full row. Keeping one record per key can therefore discard information that a full-row comparison would retain. The intended information unit must be decided before an option is chosen.

Sources for this section: [1]

A technical note corrects an intuitive model

Usage Note 1566 explains that NODUPRECS compares all variable values only with the previous observation written to output. It does not compare each observation with every other observation. The note recommends NODUPKEY with BY _ALL_ or SQL DISTINCT for removing all identical full observations.

Adjacency is the decisive detail. If two equal full rows are separated by a different row after sorting, a one-step comparison can leave both copies. This is a property of the specified procedure, not proof that one of the records is uniquely meaningful.

Sources for this section: [2]

Stable sorting needs an input order

The manual cautions that a stable sort cannot repair input whose order is not repeatable, such as some database retrievals.

The task below supplies a physical row sequence and assumes stable ordering within each key. Those assumptions let the reader reproduce the result. An unspecified retrieval order would make โ€œkeep the first rowโ€ an incomplete policy. No claim about a particular production database follows from this small example.

Sources for this section: [1]

Original five-row trace

Invented input, in order: (A,10),(A,11),(A,10),(B,20),(B,20). Assume a stable Base-SAS-like sort with EQUALS and no host-specific exception. Trace three operations: NODUPKEY by ID; NODUPRECS after sorting only by ID; and NODUPKEY by every field. Which one answers โ€œone record per IDโ€, and which answers โ€œdistinct complete rowsโ€?

Reference answer: key-only deduplication leaves (A,10),(B,20): two rows. Adjacent full-row comparison leaves (A,10),(A,11),(A,10),(B,20): four rows, because the two A,10 copies are separated. Sorting by every field and retaining distinct complete rows leaves (A,10),(A,11),(B,20): three rows. The first answers the key question; the last answers full-row equality. These supplied algorithms were checked in Python, not executed in SAS.

Sources for this section: [1] ยท [2]

Continue the chronology

Biography context

Explore Worldwide through connected lives

Connected biographies

The connected careers

Quick answers

Common questions

Is one record per ID the same as distinct full rows?
No. Different measurements under the same ID remain distinct full rows even when a key-only operation keeps only one.

Primary and institutional sources

How this history was checked

Compare the dated company records with the independent or regulatory context. Original task inputs are labelled separately from reported historical measures. This article was reviewed on 31 October 2026.

  1. SASPROC SORT, Base SAS 9.3 Procedures Guide, second edition
  2. SAS SupportUsage Note 1566: NODUPRECS