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
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;
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.