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 minimum score upto the current observation

Introduction

  • A running minimum is the smallest score seen so far within a subject — useful for worst-observed-value summaries, minimum nadir calculations, and similar clinical derivations.
  • The running minimum resets at the start of each subject so values from one subject never leak into another.
  • SAS uses RETAIN with min(score, minscore) inside a DATA step, resetting the retained value on first.usubjid.
  • Tidyverse uses group_by() + cummin(), with an Inf placeholder for NAs so missing values do not break the running calculation.
  • Base R uses ave() with a helper that replaces NAs with Inf and calls cummin() per subject.
  • This lesson also fills the rows where the original score was NA with the running minimum, so the score column becomes a monotonically non-increasing series within each subject.

Retain minimum score upto the current observation