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 ↗
← SASnRFind Maximum Value Across Multiple Variables in Each Row

Introduction

  • Clinical data often spreads repeated measures across columns — hgb_v1, hgb_v2, hgb_v3 — and a derivation needs the per-row maximum across those columns.
  • The answer is a new column whose value on each row is the largest of the listed columns, ignoring missings.
  • SAS handles this in a DATA step with the function max(of var1--varN), where the of keyword signals a variable list.
  • Tidyverse uses rowwise() + mutate(max = max(...)) to evaluate the max one row at a time.
  • Base R uses pmax() (parallel max across vectors) or apply(..., 1, max) on selected columns.
  • This lesson picks the maximum hemoglobin across three visits, so each subject ends up with a single maximum value.

Find Maximum Value Across Multiple Variables in Each Row