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?

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 901 views
  • 0 likes
  • 4 in conversation