SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Deleting duplicate rows

Accepted Solution Solved
Reply
Super Contributor
Posts: 413
Accepted Solution

Deleting duplicate rows

Hi,

suppose I have the following table:

IDName
1Mike
1Mike
2George
3Jack
3Jack
4Tan

Is it possible to delete the duplicate rows for IDs 1 and 3, but the rows where there are no duplicates, like those for IDs 2 and 4, to keep them as they are?

Thank you,


Accepted Solutions
Solution
‎12-17-2014 09:15 PM
Respected Advisor
Posts: 3,124

Re: Deleting duplicate rows

In this case, who not just:

proc sort data=dup nodupkey;

by id;

run;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,204

Re: Deleting duplicate rows

data want;

set have;

by id;

if first.id;

run;

Super Contributor
Posts: 413

Re: Deleting duplicate rows

Hi stat@sas,

I did the following including your code:

data dup;

input id name$;

datalines;

3 a

3 a

1 d

5 e

5 e

4 y

2 t

2 t

;

run;

data dup2;

set dup;

by id;

if first.id;

run;

But I get an error message:

ERROR 180-322: BY variables not properly sorted on dataset DUP

And the result that I get is:

id

name

1

3

a

It seems that the duplicate was deleted for the first row, but after that the code stopped functioning

Thank you

Trusted Advisor
Posts: 1,204

Re: Deleting duplicate rows

You need to sort dataset dup by id before performing by processing

proc sort data=dup;

by id;

run;

then try this

data dup2;

set dup;

by id;

if first.id;

run;

Solution
‎12-17-2014 09:15 PM
Respected Advisor
Posts: 3,124

Re: Deleting duplicate rows

In this case, who not just:

proc sort data=dup nodupkey;

by id;

run;

Trusted Advisor
Posts: 1,204

Re: Deleting duplicate rows

Thanks Haikuo - Yes, this is a better solution.

Super Contributor
Posts: 413

Re: Deleting duplicate rows

Thank you Hai.kuo and stat@sas !!!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 473 views
  • 3 likes
  • 3 in conversation