Help using Base SAS procedures

Duplicates

Reply
Contributor
Posts: 73

Duplicates

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
Super Contributor
Posts: 259

Re: Duplicates

Posting the code used to accomplish the task increases the chance to get useful answers.
Contributor
Posts: 73

Re: Duplicates

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
Respected Advisor
Posts: 3,887

Re: Duplicates

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
Contributor
Posts: 73

Re: Duplicates

Thanks, please see resulting error

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

Fred
Contributor
Posts: 73

Re: Duplicates

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
Ask a Question
Discussion stats
  • 5 replies
  • 156 views
  • 0 likes
  • 3 in conversation