Dear all,
I need to delete observations for a variable when a certain condition happens. Let's me give you an example of my dataset:
data have;
input id variable1 variable_year;
datalines;
1 0 2000
1 0 2001
1 0 2002
1 1 2003
2 0 2007
2 1 2008
3 0 2003
3 0 2004
3 0 2005
4 1 2006
4 . 2007
5 1 2010
5 . 2011
5 . 2012
6 1 2001
6 . 2002
6 . 2003
6 . 2004
6 . 2005
;
run;
What I want as a result would be something like that:
I need to delete observations for a variable when a certain condition happens. Let's me give you an example of my dataset:
data want;
input id variable1 variable_year;
datalines;
1 0 2000
1 0 2001
1 0 2002
1 1 2003
2 0 2007
2 1 2008
3 0 2003
3 0 2004
3 0 2005
;
run;
Si I want to delete the observations by id variable when variable1 = 1 and variable_year = first row. Does anyone could help ?
I have tried this, but it does not work because I just delete the row for that observation.
data want;
set have;
if variable1 = 1 and variable_year=first.variable_year then delete;
run;