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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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