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

Findings Domains (LB/VS) & the SDTM --DTC Date Standard

Long-structured findings domains and ISO date handling.

Learning objectives

  • 1Build a findings domain (e.g., LB) row structure.
  • 2Derive --DTC ISO dates and --DY study days.
  • 3Apply --TESTCD/--TEST controlled terminology.
  • 4Sequence records with --SEQ.

Key SAS® → R comparison

TaskSAS®R
Findings rowstranspose to longpivot_longer()
--SEQby-group countergroup_by()+row_number()
--DYdate diff +1 rulelubridate arithmetic

Code examples

Sequencing LB records
SAS®
data lb; set lb;
  by usubjid;
  if first.usubjid then lbseq=0;
  lbseq+1;
run;
R
lb <- lb |>
  arrange(usubjid, lbdtc, lbtestcd) |>
  group_by(usubjid) |>
  mutate(LBSEQ = row_number()) |>
  ungroup()

Note: row_number() within a group gives a clean, reproducible --SEQ without retain logic.

Explanation

Findings domains are inherently long — one row per subject, test and timepoint — so they are built by pivoting raw wide data and then standardizing test codes, units and dates. The --DTC variables hold ISO 8601 strings and --DY is derived with the standard no-day-zero rule.

Record sequencing (--SEQ) is a grouped row_number(), which replaces retain-based counters and is trivial to verify because the ordering keys are explicit in the arrange().

Practice exercise

Construct an LB domain from raw labs: pivot to long, assign LBTESTCD/LBTEST, derive LBDTC and LBDY, and number records with LBSEQ per subject.