BookmarkSubscribeRSS Feed
fredbell
Fluorite | Level 6
Hello

If i have two records that are not an exact duplicate but contain a duplicate ID field, how can i create a dataset containing both records?

I've only been able to return the first record to this point, the second is deleted.

Thanks

Fred
5 REPLIES 5
andreas_lds
Jade | Level 19
Posting the code used to accomplish the task increases the chance to get useful answers.
fredbell
Fluorite | Level 6
Ok below is what i am using, it only keeps the first record and deletes the other.


proc sort data= ccar.hierarchy out=ccar.out nodupkey dupout=ccar.dupes_Level_7_ID;
where SiteID = 80;
by Level_7_id;
run;

Fred
Patrick
Opal | Level 21
proc sort data= ccar.hierarchy out=ccar.out;
where SiteID = 80;
by Level_7_id;
run;

data ccar.out ccar.dupes_Level_7_ID;
set ccar.out;
by Level_7_id;
if first.Level_7_id and last.Level_7_id then output ccar.out;
else
do;
if first.Level_7_id then output ccar.out
output ccar.dupes_Level_7_ID;
end;
run;

HTH
Patrick
fredbell
Fluorite | Level 6
Thanks, please see resulting error

ERROR 455-185: Data set was not specified on the DATA statement.

Fred
fredbell
Fluorite | Level 6
Hi everyone

I used this code and it worked, finally.

proc sort data= ccar.hierarchy out=ccar.out;
where SiteID = 80;
by Level_7_id;
run;

data single dup;
set ccar.out;
by Level_7_ID;
if first.Level_7_ID and last.Level_7_ID then output single;
else output dup;
run;


Fred

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 1346 views
  • 0 likes
  • 3 in conversation