BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ilikesas
Barite | Level 11

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,

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

In this case, who not just:

proc sort data=dup nodupkey;

by id;

run;

View solution in original post

6 REPLIES 6
stat_sas
Ammonite | Level 13

data want;

set have;

by id;

if first.id;

run;

ilikesas
Barite | Level 11

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

stat_sas
Ammonite | Level 13

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;

Haikuo
Onyx | Level 15

In this case, who not just:

proc sort data=dup nodupkey;

by id;

run;

stat_sas
Ammonite | Level 13

Thanks Haikuo - Yes, this is a better solution.

ilikesas
Barite | Level 11

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

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

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