BookmarkSubscribeRSS Feed
Smitha9
Fluorite | Level 6

Hi,

I have a dataset:

ID      set

A        1

A        2

A        1

B        2

B        1

C        2

 

I want to remove the only first set of duplicate.

I want:

A    2

B    2

C    2

 

Can I do that in SAS?

thank you in advance.

3 REPLIES 3
Reeza
Super User

Assuming first means lowest? What happens if a record has duplicates in the 2s?

 

proc sort data=have;
by ID set;
run;

data want;
set have;
by ID set;
retain counter 0;
if first.id then counter+1;
if counter=2;
run;

@Smitha9 wrote:

Hi,

I have a dataset:

ID      set

A        1

A        2

A        1

B        2

B        1

C        2

 

I want to remove the only first set of duplicate.

I want:

A    2

B    2

C    2

 

Can I do that in SAS?

thank you in advance.


 

ballardw
Super User

Suppose you  have a dataset:

ID set

A 1

A 2

A 3

A 1

A 2

A 2

A 3

B 2

B 1

C 2

 

What would the result look like? Your "rule" might be a bit understated. Lists of output with some description of rules and be somewhat misleading. Now there are two different duplicates for A and a non-duplicated version. So, what is the rule?

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 714 views
  • 0 likes
  • 4 in conversation