I have a data and I want to keep records where their test starts <=80 and, it doesn’t matter if the number is greater of less than after identifying the first obs that is <=80
data want;
set have;
by id;
*hold values across rows;
retain output_flag;
*reset flag for each new ID;
if first.id then output_flag=0;
*set flag when the test value <=80 - this will never be reset until a new id is reached;
if test <=80 then output_flag=1;
*output to data set;
if output_flag then output;
run;
I have a data and I want to keep records where their test starts <=80 and, it doesn’t matter if the number is greater of less than after identifying the first obs that is <=80
data want;
set have;
by id;
retain outflag;
if first.id then outflag=0;
if test le 80 then outflag=1;
if outflag;
drop outflag;
run;
You do not mention if "test" will ever be missing. Missing is always less than any value. So if you have missing values for test you may need to expand on the rules.
data want;
set have;
by id;
*hold values across rows;
retain output_flag;
*reset flag for each new ID;
if first.id then output_flag=0;
*set flag when the test value <=80 - this will never be reset until a new id is reached;
if test <=80 then output_flag=1;
*output to data set;
if output_flag then output;
run;
I have a data and I want to keep records where their test starts <=80 and, it doesn’t matter if the number is greater of less than after identifying the first obs that is <=80
ID
test
1
100
1
70
1
200
2
85
2
350
2
65
3
80
3
75
3
120
ID
test
1
70
1
200
2
65
3
80
3
75
3
120
SAS Innovate 2025: Register Now
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9. Sign up by Dec. 31 to get the 2024 rate of just $495. Register now!