Solved
New Contributor
Posts: 3

# How to separate and store unique and duplicate records in two different datasets using proc sort

data excess;

input id n1;

cards;

10 10

10 20

10 20

10 30

10 40

10 40

10 50

;

run;

now using proc sort separate and store  only unique records in dataA and all other records in dataB .

Accepted Solutions
Solution
‎10-05-2014 12:45 PM
PROC Star
Posts: 8,164

## Re: How to separate and store unique and duplicate records in two different datasets using proc sort

I think that the following will achieve what you want:

proc sort data = excess ;

by id n1;

run;

data want dups;

set excess;

by id n1;

if first.n1 and last.n1 then output want;

else output dups;

run;

All Replies
Posts: 1,147

## Re: How to separate and store unique and duplicate records in two different datasets using proc sort

try

proc sort data = excess out=wantdupout=dups nodupkey;

by id n1;

run;

the want dataset have unique records and dups have all other records. Hope this helps.

Thanks,

Thanks,
Jag
New Contributor
Posts: 3

## Re: How to separate and store unique and duplicate records in two different datasets using proc sort

dataset want should be like this

id        n1

10     10

10     30

10     50

and dataset dups

id    n1

10      20

10      20

10      40

10      40

Posts: 1,147

## Re: How to separate and store unique and duplicate records in two different datasets using proc sort

Thanks for providing the desired output. please try

dups dataset has duplicate records and unique will have unique records.

proc sort data=excess out=dups UNIQUEOUT= unique NOUNIQUEKEY;

by id n1;

run;

Thanks,

Jag

Thanks,
Jag
Solution
‎10-05-2014 12:45 PM
PROC Star
Posts: 8,164

## Re: How to separate and store unique and duplicate records in two different datasets using proc sort

I think that the following will achieve what you want:

proc sort data = excess ;

by id n1;

run;

data want dups;

set excess;

by id n1;

if first.n1 and last.n1 then output want;

else output dups;

run;

New Contributor
Posts: 3

## Re: How to separate and store unique and duplicate records in two different datasets using proc sort

thanks

🔒 This topic is solved and locked.