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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.