BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ram999
Calcite | Level 5

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...

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20

Use proc sort with nodupkey option 🙂

 

proc sort data = demo nodupkey;
	by x y z a;
run;
Ram999
Calcite | Level 5
🙂
Kurt_Bremser
Super User

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;
Ram999
Calcite | Level 5
Thank you
Miracle
Barite | Level 11

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;
ballardw
Super User

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.

Ram999
Calcite | Level 5
Okay, sure Thank you 🙂

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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