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...
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;
Use proc sort with nodupkey option 🙂
proc sort data = demo nodupkey;
by x y z a;
run;
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;
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;
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.