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

Hi

 

I need help deleting observations based on other observations using SAS 9.4.

I have a number of people with an ID-number a year and a score from that year.

I would like to keep the first observation for one person everytime the score changes, also if the person has had that score before. I want to delete subsequent scores that are the same. Can someone help me with that?

 

data have;

input id year score;

1 2000 0

1 2002 1

1 2003 1

1 2004 0

 

2 2000 0

2 2003 0

 

3 2001 2

3 2003 4

3 2006 3

3 2007 3

;

run;

 

What I want:

1 2000 0

1 2002 1

1 2004 0

 

2 2000 0

 

3 2001 2

3 2003 4

3 2007 3

 

Thank you in advance.

Regards,

RTN

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

HI @RTN  Do you mean this?

 


data have;

input id year score;
cards;
1 2000 0
1 2002 1
1 2003 1
1 2004 0
2 2000 0
2 2003 0
3 2001 2
3 2003 4
3 2006 3
3 2007 3
;

data want;
set have;
by id score notsorted;
if first.score;
run;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

HI @RTN  Do you mean this?

 


data have;

input id year score;
cards;
1 2000 0
1 2002 1
1 2003 1
1 2004 0
2 2000 0
2 2003 0
3 2001 2
3 2003 4
3 2006 3
3 2007 3
;

data want;
set have;
by id score notsorted;
if first.score;
run;
RTN
Calcite | Level 5 RTN
Calcite | Level 5
Yes thank you!
That works perfectly.

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

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 705 views
  • 0 likes
  • 2 in conversation