A little announcement. A lot to explore.

Happy learning!

Explore lessons, including SAS & R programs and practice data.

Search lessons

Type at least 3 characters to see matching lessons.

Open SAS ↗Open R ↗
← SASnRRetain maximum score upto the current observation

Introduction

  • The mirror of the running-minimum lesson: carry forward the largest score seen so far within each subject.
  • Running maximums show up in worst-observed-value summaries on the high side — highest lab value observed to date, peak pain score, and similar clinical derivations.
  • As with the minimum, the running maximum resets at the start of each subject so no values leak across subjects.
  • SAS uses RETAIN with max(score, maxscore), resetting on first.usubjid.
  • Tidyverse uses group_by() + cummax(), with -Inf as the NA placeholder so missing values never win the maximum.
  • Base R uses ave() with a helper that masks NAs as -Inf and calls cummax() within each subject.

Retain maximum score upto the current observation