11  Creating ADaM: ADSL from SDTM-like Inputs

library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(tidyr)
library(lubridate)

Attaching package: 'lubridate'
The following objects are masked from 'package:base':

    date, intersect, setdiff, union

We simulate minimal SDTM-like DM and EX to illustrate ADSL creation. If available, replace with your own data/sdtm/*.sas7bdat.

# DM
dm <- tibble::tibble(
  STUDYID = "XYZ123",
  USUBJID = sprintf("XYZ-%03d", 1:10),
  ARM = rep(c("Placebo","Active"), length.out=10),
  AGE = c(55, 62, 47, 50, 71, 66, 45, 59, 53, 68),
  SEX = rep(c("M","F"), length.out=10),
  RANDDT = as.Date("2025-01-15") + sample(0:20, 10, replace=TRUE)
)

# EX (first dose date)
ex <- tibble::tibble(
  USUBJID = dm$USUBJID,
  EXSTDTC = dm$RANDDT + sample(0:3, 10, replace=TRUE)
)

11.1 Build ADSL

adsl <- dm |>
  left_join(ex, by="USUBJID") |>
  transmute(
    STUDYID, USUBJID,
    TRT01P = ARM,
    TRT01PN = as.integer(factor(ARM, levels=c("Placebo","Active"))),
    AGE, SEX,
    RANDDT,
    TRTSDT = EXSTDTC,
    TRT01A = TRT01P,          # assume planned == actual for demo
    TRT01AN = TRT01PN
  )
adsl
# A tibble: 10 × 10
   STUDYID USUBJID TRT01P  TRT01PN   AGE SEX   RANDDT     TRTSDT     TRT01A 
   <chr>   <chr>   <chr>     <int> <dbl> <chr> <date>     <date>     <chr>  
 1 XYZ123  XYZ-001 Placebo       1    55 M     2025-01-18 2025-01-18 Placebo
 2 XYZ123  XYZ-002 Active        2    62 F     2025-01-30 2025-01-30 Active 
 3 XYZ123  XYZ-003 Placebo       1    47 M     2025-01-15 2025-01-15 Placebo
 4 XYZ123  XYZ-004 Active        2    50 F     2025-01-26 2025-01-28 Active 
 5 XYZ123  XYZ-005 Placebo       1    71 M     2025-01-31 2025-02-03 Placebo
 6 XYZ123  XYZ-006 Active        2    66 F     2025-02-01 2025-02-03 Active 
 7 XYZ123  XYZ-007 Placebo       1    45 M     2025-02-04 2025-02-07 Placebo
 8 XYZ123  XYZ-008 Active        2    59 F     2025-01-15 2025-01-16 Active 
 9 XYZ123  XYZ-009 Placebo       1    53 M     2025-01-19 2025-01-20 Placebo
10 XYZ123  XYZ-010 Active        2    68 F     2025-01-19 2025-01-19 Active 
# ℹ 1 more variable: TRT01AN <int>

Note: Real ADSL creation must follow ADaM IG (derive flags, dates, imputations, populations). This example is educational only.

Exercises 1. Add analysis populations (e.g., SAFFL, FASFL) based on simple rules. 2. Derive AGEGR1 as <65 / ≥65 and use ordered factor. 3. Add a treatment end date TRTEDT and compute treatment duration.