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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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