SAS Sort Procedure
The SORT procedure in SAS sorts data. It can optionally remove duplicated cases.
Contents
Syntax
Sort a table, either in-place or into a new table.
proc sort data=LIBREF.TABLE1 out=LIBREF.TABLE2;
by VAR1;
run;Deduplicate a table. Produce two tables: unique cases to TABLE2 and removed (duplicate) cases to TABLE3.
proc sort data=LIBREF.TABLE1 out=LIBREF.TABLE2 nodupkey dupout=LIBREF.TABLE3;
by VARLIST;
run;
Examples
Basic Deduplication
proc sort data=LIBREF.OLDTABLE
out=LIBREF.NEWTABLE
nodupkey
dupout=LIBREF.REMOVEDCASES
by ID;
run;
Perfect Duplicates
To remove perfect duplicates...
use _all_ on the BY statement
substitute the nodupkey option with noduprecs
Deduplication With Criteria
If there should be a preference between which case is kept, use another SORT procedure before the one specifying nodupkey.
proc sort data=LIBREF.OLDTABLE
out=LIBREF.TABLE1;
by ID descending QUALITY DATE;
run;
proc sort data=LIBREF.TABLE1
out=LIBREF.NEWTABLE
nodupkey
dupout=LIBREF.TABLE2
by ID;
run;
