DATA Step, Macro, Functions and more

Seperate duplicate records

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

Seperate duplicate records

[ Edited ]

data demo;
infile datalines;
input record x y z a;
cards;
1 34 54 65 76
2 34 54 65 76
3 34 54 65 76
4 34 54 65 76
5 98 45 09 56
6 12 43 98 87
7 12 43 98 87
8 76 93 68 34
;

 

From above dataset i want to separate duplicate records like

1st,2nd,3rd,4th,6th and 7th are duplicates.

How can i get that?

Thnaks in advance...

 

 

 


Accepted Solutions
Solution
‎04-11-2017 02:39 AM
Super User
Posts: 7,766

Re: sas

If you want to get all duplicates from your original dataset, you need to use the dupout= option to get a reference dataset:

proc sort data=demo;
by x y z a;
run;

proc sort
  data=demo
  out=test /* avoids overwriting the original dataset */
  dupout=duptest (drop=record)
  nodupkey
;
by x y z a;
run;

data want;
merge
  demo
  duptest (in=dup)
;
by x y z a;
if dup;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
PROC Star
Posts: 735

Re: sas

Use proc sort with nodupkey option Smiley Happy

 

proc sort data = demo nodupkey;
	by x y z a;
run;
Occasional Contributor
Posts: 11

Re: sas

Smiley Happy
Solution
‎04-11-2017 02:39 AM
Super User
Posts: 7,766

Re: sas

If you want to get all duplicates from your original dataset, you need to use the dupout= option to get a reference dataset:

proc sort data=demo;
by x y z a;
run;

proc sort
  data=demo
  out=test /* avoids overwriting the original dataset */
  dupout=duptest (drop=record)
  nodupkey
;
by x y z a;
run;

data want;
merge
  demo
  duptest (in=dup)
;
by x y z a;
if dup;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 11

Re: sas

Posted in reply to KurtBremser
Thank you
Regular Contributor
Posts: 228

Re: sas

maybe this?

data demo;
infile datalines;
input record x y z a;
cards;
1 34 54 65 76
2 34 54 65 76
3 34 54 65 76
4 34 54 65 76
5 98 45 09 56
6 12 43 98 87
7 12 43 98 87
8 76 93 68 34
;
run;
proc sort data=demo out=dup_rec nouniquekey uniqueout=unique_rec; by x y z a; run;
proc sort data=dup_rec; by record; run;
proc print data=dup_rec noobs; run;
proc sort data=unique_rec; by record; run;
proc print data=unique_rec noobs; run;
Super User
Posts: 11,343

Re: sas

Please show what your desired output would look like and whether you need a SAS data set or a report.

 

And please use a description subject line for you post like: Separate Duplicates. SAS as a subject is not very helpful since this is a SAS community forum.

Occasional Contributor
Posts: 11

Re: sas

Okay, sure Thank you Smiley Happy
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 170 views
  • 0 likes
  • 5 in conversation