BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tom
Super User Tom
Super User

Yes. It is only use the POINT= on the first observation so KEEP= is not needed as values re-read will be the same values.

 

The easiest to understand method is to use the RETAIN statement to keep the value of SCORE from the first observation.

data want;
  set reading;
  by id score;
  if first.score then low_score=score;
  retain low_score;
run;

Two things to check.

1) The variable retained (LOW_SCORE) cannot exist on the source dataset (READING) or else its value will be overwritten when the SET statement next executes.

2) If there are missing values of SCORE they will sort before any valid value.  In that case you might find the PROC SQL solution easiest to understand.

proc sql;
  create table want as
    select *,min(score) as low_score
    from reading
    group by id 
  ;
quit;

Note this uses a SAS specific feature where it will re-merge the LOW_SCORE value calculated at the ID level back onto all of the individual observations for that value of ID.

 

Or possibly the double "DOW" (do while) loops.

data want;
do until(last.id);
  set reading;
  by id;
  low_score=min(low_score,score);
end;
do until(last.id);
  set reading;
  by id;
  output;
end;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 15 replies
  • 12578 views
  • 14 likes
  • 6 in conversation