30-Day Course
Clinical SAS → R
Day 23 of 30·SDTM Implementation

Intro to admiral: Derivations the Standardized Way

Using admiral helper functions for common SDTM/ADaM derivations.

Learning objectives

  • 1Install and load admiral and dummy data.
  • 2Use derive_vars_dt() and related helpers.
  • 3Understand admiral's predictable function naming.
  • 4Combine admiral helpers within a dplyr pipeline.

Key SAS® → R comparison

TaskSAS®R
Date imputationcustom macroadmiral::derive_vars_dt()
Merge lookup varsmerge by keyadmiral::derive_vars_merged()
First/last flagfirst./last.admiral::derive_var_extreme_flag()

Code examples

Deriving an analysis date
SAS®
/* macro to impute partial dates,
   then compute analysis date */
R
library(admiral)
adlb <- adlb |>
  derive_vars_dt(
    new_vars_prefix = "AST",
    dtc             = LBDTC,
    highest_imputation = "M"
  )

Note: admiral functions are documented, tested and validated by the community — reducing per-study macro maintenance.

Explanation

admiral packages the most common clinical derivations — imputed dates, merged lookups, extreme-value flags, treatment-emergent logic — as documented, unit-tested functions with a consistent derive_* naming scheme. This replaces bespoke macro libraries with shared, validated tooling.

Because each helper slots into a dplyr pipeline and operates on standard CDISC variable names, you assemble derivations declaratively while leaning on community-maintained logic for the fiddly imputation rules.

Practice exercise

Use admiral::derive_vars_dt() to create an imputed analysis start date from a partial --DTC, then derive_vars_merged() to bring treatment dates from ADSL into a BDS dataset.