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

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
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;


@hjjijkkl wrote:

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

 


 

View solution in original post

3 REPLIES 3
hjjijkkl
Pyrite | Level 9
the 2nd table is the output i wanted
ballardw
Super User

Something like this should get you started.

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.

Reeza
Super User
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;


@hjjijkkl wrote:

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 693 views
  • 2 likes
  • 3 in conversation