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 ↗
← SASnRCOALESCE: Pick the First Non-Missing Value

Introduction

  • Clinical ADaM derivations often need fallback logic: use the primary value if it exists, otherwise fall back to a secondary or tertiary source.
  • A common example is deriving the analysis start date — we prefer AESTDTC (adverse event start date), but if that is missing we fall back to RFSTDTC (reference start date).
  • SAS splits this into two functions: COALESCE() for numeric values and COALESCEC() for character values. Mixing types causes an error.
  • R has a single coalesce() function from dplyr that handles both types. Base R uses ifelse() chains or a custom function built with Reduce().
  • This lesson demonstrates both character (date) and numeric (score) fallback scenarios.

COALESCE: Pick the First Non-Missing Value