ADTTE, time to event
A time-to-event analysis asks how long until something happens. Some subjects have the event. The others leave the study first. For them, you know only that the event did not happen up to a date. They are censored at that date. ADTTE stores both kinds of subject in one row per subject and parameter:
| Variable | Meaning |
|---|---|
STARTDT |
the start of the clock, here the first dose |
ADT |
the date of the event, or the censoring date |
AVAL |
the time in days: ADT - STARTDT + 1 |
CNSR |
the censor flag: 0 = the event happened, 1 = censored |
EVNTDESC |
what gave the date: the event, or the reason for censoring |
SRCDOM, SRCVAR, SRCSEQ |
the data set, the variable and the row that gave the date, for traceability |
The pilot study has one such parameter: TTDE, the time to the first dermatologic event. A subject without such an event is censored at the end of the study, RFENDT. The programs read data/adsl.rds from chapter 9 and data/adae.rds from chapter 11.
12.1 The event: a dermatologic adverse event
Section titled “12.1 The event: a dermatologic adverse event”The pilot defines the dermatologic events with a customized query: a list of terms that the specification defines, named CQ01. The reference ADAE of the pilot carries it in CQ01NAM. Your ADAE of chapter 11 does not have it, so write the definition first. An AE is a dermatologic event when:
- its preferred term contains APPLICATION, DERMATITIS, ERYTHEMA or BLISTER, or
- its system organ class is SKIN AND SUBCUTANEOUS TISSUE DISORDERS, except the terms COLD SWEAT, HYPERHIDROSIS and ALOPECIA.
# Chapter 12: the event of the pilot TTE parameter: a dermatologic adverse eventlibrary(dplyr)
# The specification of the customized query CQ01, "DERMATOLOGIC EVENTS"is_derm <- function(aedecod, aebodsys) { grepl("APPLICATION|DERMATITIS|ERYTHEMA|BLISTER", aedecod) | (aebodsys == "SKIN AND SUBCUTANEOUS TISSUE DISORDERS" & !aedecod %in% c("COLD SWEAT", "HYPERHIDROSIS", "ALOPECIA"))}
derm <- readRDS("data/adae.rds") |> filter(is_derm(AEDECOD, AEBODSYS))
derm |> summarise(events = n(), subjects = n_distinct(USUBJID), .by = TRTEMFL)#> # A tibble: 2 x 3#> TRTEMFL events subjects#> <chr> <int> <int>#> 1 Y 476 152#> 2 <NA> 17 9
derm |> count(AEDECOD, sort = TRUE) |> print(n = 5)#> # A tibble: 35 x 2#> AEDECOD n#> <chr> <int>#> 1 PRURITUS 84#> 2 APPLICATION SITE PRURITUS 78#> 3 ERYTHEMA 59#> 4 APPLICATION SITE ERYTHEMA 46#> 5 RASH 45#> # i 30 more rows
derm |> filter(USUBJID == "01-701-1015") |> select(USUBJID, AESEQ, AEDECOD, ASTDT, TRTEMFL)#> # A tibble: 2 x 5#> USUBJID AESEQ AEDECOD ASTDT TRTEMFL#> <chr> <dbl> <chr> <date> <chr>#> 1 01-701-1015 1 APPLICATION SITE ERYTHEMA 2014-01-03 Y#> 2 01-701-1015 2 APPLICATION SITE PRURITUS 2014-01-03 Yis_derm()holds the definition, so the rule is written once.grepl()isTRUEwhen the text contains one of the words;|in the pattern means “or”. Chapter 3 explains patterns.- 476 treatment-emergent dermatologic events belong to 152 subjects. 17 more events started before the first dose: they do not count.
- The most frequent terms are pruritus (itching) and application site reactions. The study drug was given as a patch on the skin.
Subject 01-701-1015 has two dermatologic events, both on 2014-01-03: AESEQ 1 and 2.
12.2 ADTTE by hand
Section titled “12.2 ADTTE by hand”# Chapter 12: ADTTE by hand: time to the first dermatologic event, or censoringlibrary(dplyr)
is_derm <- function(aedecod, aebodsys) { grepl("APPLICATION|DERMATITIS|ERYTHEMA|BLISTER", aedecod) | (aebodsys == "SKIN AND SUBCUTANEOUS TISSUE DISORDERS" & !aedecod %in% c("COLD SWEAT", "HYPERHIDROSIS", "ALOPECIA"))}
adsl <- readRDS("data/adsl.rds") |> filter(SAFFL == "Y") |> select(STUDYID, USUBJID, TRTSDT, RFENDT)
# Step 010: the first treatment-emergent dermatologic event of each subjectfirst_derm <- readRDS("data/adae.rds") |> filter(TRTEMFL == "Y", is_derm(AEDECOD, AEBODSYS)) |> arrange(USUBJID, ASTDT, AESEQ) |> slice_head(n = 1, by = USUBJID) |> select(USUBJID, ASTDT, AESEQ)
# Step 020: one row per subject. Start from ADSL, so no subject is lostadtte_hand <- adsl |> left_join(first_derm, by = join_by(USUBJID), relationship = "one-to-one") |> mutate( PARAMCD = "TTDE", PARAM = "Time to First Dermatologic Event", STARTDT = TRTSDT, event = !is.na(ASTDT), ADT = if_else(event, ASTDT, RFENDT), CNSR = if_else(event, 0L, 1L), EVNTDESC = if_else(event, "Dermatologic event", "Study completion date"), SRCDOM = if_else(event, "ADAE", "ADSL"), SRCVAR = if_else(event, "ASTDT", "RFENDT"), SRCSEQ = if_else(event, AESEQ, NA) ) |> # Step 030: AVAL in days. The first day counts: an event on the day of the # first dose has AVAL = 1 mutate(AVAL = as.numeric(ADT - STARTDT) + 1) |> select( STUDYID, USUBJID, PARAMCD, PARAM, STARTDT, ADT, AVAL, CNSR, EVNTDESC, SRCDOM, SRCVAR, SRCSEQ )
adtte_hand |> count(CNSR, EVNTDESC)#> # A tibble: 2 x 3#> CNSR EVNTDESC n#> <int> <chr> <int>#> 1 0 Dermatologic event 152#> 2 1 Study completion date 102
adtte_hand |> filter(USUBJID %in% c("01-701-1015", "01-701-1033")) |> select(USUBJID, STARTDT, ADT, AVAL, CNSR, SRCVAR)#> # A tibble: 2 x 6#> USUBJID STARTDT ADT AVAL CNSR SRCVAR#> <chr> <date> <date> <dbl> <int> <chr>#> 1 01-701-1015 2014-01-02 2014-01-03 2 0 ASTDT#> 2 01-701-1033 2014-03-18 2014-04-14 28 1 RFENDT
saveRDS(adtte_hand, "data/adtte_hand.rds")Three rules carry this program:
- Every subject gets exactly one row. The program starts from ADSL, not from the events, and adds the events with a left join. A subject without an event must not disappear: that subject is the censored one.
relationship = "one-to-one"checks thatfirst_dermhas one row per subject. - The first event wins. Step 010 sorts the events by date and
AESEQand keeps the first row of each subject withslice_head(n = 1, by = USUBJID). A second rash later does not change the time to the first one. - The first day counts.
AVAL = ADT - STARTDT + 1. An event on the day of the first dose hasAVAL = 1, not 0.
The column event holds the answer to one question: did the subject have an event? Each if_else() then picks the event value or the censoring value. 0L and 1L are whole numbers (integers); CNSR is an integer in ADaM.
The safety population has 254 subjects: 152 have an event, and 102 are censored at the end of study. Subject 01-701-1015 started on 2014-01-02 and had the event on 2014-01-03: AVAL = 2, CNSR = 0. Subject 01-701-1033 had no dermatologic event. It is censored at its end of study, 2014-04-14: AVAL = 28, CNSR = 1.
SRCDOM, SRCVAR and SRCSEQ say where each date came from: ASTDT of ADAE row AESEQ 1 for 01-701-1015, RFENDT of ADSL for 01-701-1033. A reviewer can trace every time back to its source.
12.3 ADTTE with admiral
Section titled “12.3 ADTTE with admiral”admiral describes a time-to-event parameter by its sources: where the events come from, and where the censoring dates come from. One call then applies the three rules of section 12.2.
# Chapter 12: the same ADTTE with admiral: an event, a censoring, one calllibrary(dplyr)library(admiral)
adsl <- readRDS("data/adsl.rds") |> filter(SAFFL == "Y")adae <- readRDS("data/adae.rds") |> mutate( CQ01NAM = if_else( grepl("APPLICATION|DERMATITIS|ERYTHEMA|BLISTER", AEDECOD) | (AEBODSYS == "SKIN AND SUBCUTANEOUS TISSUE DISORDERS" & !AEDECOD %in% c("COLD SWEAT", "HYPERHIDROSIS", "ALOPECIA")), "DERMATOLOGIC EVENTS", NA ) )
derm_event <- event_source( dataset_name = "adae", filter = TRTEMFL == "Y" & CQ01NAM == "DERMATOLOGIC EVENTS", date = ASTDT, order = exprs(AESEQ), set_values_to = exprs( EVNTDESC = "Dermatologic event", SRCDOM = "ADAE", SRCVAR = "ASTDT", SRCSEQ = AESEQ ))end_of_study <- censor_source( dataset_name = "adsl", date = RFENDT, set_values_to = exprs( EVNTDESC = "Study completion date", SRCDOM = "ADSL", SRCVAR = "RFENDT" ))
adtte <- derive_param_tte( dataset_adsl = adsl, start_date = TRTSDT, event_conditions = list(derm_event), censor_conditions = list(end_of_study), source_datasets = list(adsl = adsl, adae = adae), set_values_to = exprs( PARAMCD = "TTDE", PARAM = "Time to First Dermatologic Event" )) |> derive_vars_duration(new_var = AVAL, start_date = STARTDT, end_date = ADT) |> select( STUDYID, USUBJID, PARAMCD, PARAM, STARTDT, ADT, AVAL, CNSR, EVNTDESC, SRCDOM, SRCVAR, SRCSEQ )
adtte |> count(CNSR, EVNTDESC)#> # A tibble: 2 x 3#> CNSR EVNTDESC n#> <int> <chr> <int>#> 1 0 Dermatologic event 152#> 2 1 Study completion date 102
saveRDS(adtte, "data/adtte.rds")event_source()describes the events: the data set (dataset_name), the rows (filter), the date (date), the tie-break (order) and the values to set (set_values_to). Here the program addsCQ01NAMto ADAE first, the way the reference ADAE has it, and filters on it.censor_source()describes the censoring dates: hereRFENDTof ADSL. ItsCNSRis 1, unless you give another value withcensor.derive_param_tte()takes the first event of each subject. A subject without an event gets the last censoring date. It addsSTARTDTfromstart_date, and thePARAMCDandPARAMofset_values_to.derive_vars_duration()computesAVALfromSTARTDTandADT. It adds 1 by default (add_one = TRUE): the first day counts.
The result has the same counts as the program by hand: 152 events and 102 censored. These are also the numbers of the SAS book, which used the reference ADAE of the pilot. Your definition of the dermatologic events finds the same subjects.
12.4 Compare: by hand and admiral
Section titled “12.4 Compare: by hand and admiral”# Chapter 12: ADTTE by hand against admiral. There is no reference ADTTElibrary(diffdf)
# derive_param_tte() does not keep the labels of ADSL: compare the values onlyadtte_hand <- readRDS("data/adtte_hand.rds") |> haven::zap_label()adtte <- readRDS("data/adtte.rds") |> haven::zap_label()
diffdf(adtte_hand, adtte, keys = c("USUBJID", "PARAMCD"))#> No issues were found!
# the time-to-event data sets in pharmaverseadamgrep("adtte", data(package = "pharmaverseadam")$results[, "Item"], value = TRUE)#> [1] "adtte_onco"The two versions agree. derive_param_tte() does not keep the labels of ADSL, so the program removes the labels before it compares.
This time there is no reference to compare with. pharmaverseadam has only adtte_onco, a time-to-event data set of an oncology example study, not of the pilot. So the double programming is the check: two independent programs, one by hand and one with admiral, that give the same 254 rows.
12.5 What ADTTE is for: a Kaplan-Meier curve
Section titled “12.5 What ADTTE is for: a Kaplan-Meier curve”A Kaplan-Meier curve shows, day by day, the share of subjects who did not have the event yet. A censored subject counts as “without the event” up to its censoring date, and then leaves the count. That is why ADTTE needs both AVAL and CNSR.
# Chapter 12: what ADTTE is for. A Kaplan-Meier curve for each armlibrary(dplyr)library(ggsurvfit)
adsl <- readRDS("data/adsl.rds") |> select(USUBJID, TRT01A)adtte <- readRDS("data/adtte.rds") |> left_join(adsl, by = join_by(USUBJID), relationship = "one-to-one")
# Surv() wants 1 for an event: the opposite of CNSRsurvfit2(Surv(AVAL, 1 - CNSR) ~ TRT01A, data = adtte) |> ggsurvfit() + add_censor_mark() + labs( x = "Days since the first dose", y = "Subjects without a dermatologic event" )#> [figure 1: /figs/12_5_km_plot-1.png]
Surv(AVAL, 1 - CNSR)of the package survival pairs the time with the event indicator.Surv()wants 1 for an event, so the program gives it1 - CNSR.survfit2()andggsurvfit()of the package ggsurvfit estimate the curve for each arm and draw it.add_censor_mark()draws a small cross at each censoring.
The two xanomeline arms fall fast in the first weeks. The drug was given as a skin patch, and many subjects on the drug had a skin reaction early. Chapter 14 makes figures like this one ready for a report.
12.6 Summary
Section titled “12.6 Summary”- ADTTE has one row per subject and parameter: an event (
CNSR = 0) or a censoring (CNSR = 1), with the date inADTand the time inAVAL. - Write the event definition once, from the specification: here the dermatologic query CQ01.
- Start from ADSL so that no subject is lost. The first event wins. The first day counts:
AVAL = ADT - STARTDT + 1. - Keep the source of each date in
SRCDOM,SRCVARandSRCSEQ. - admiral:
event_source(),censor_source(),derive_param_tte()andderive_vars_duration(). - When there is no reference, two independent programs that agree are the check.
- A Kaplan-Meier curve uses
AVALandCNSRtogether:Surv(AVAL, 1 - CNSR).
12.7 Exercises
Section titled “12.7 Exercises”Exercise 12-1. Before you trust AVAL, check the event source. How many treatment-emergent dermatologic events have no start date, an imputed start date, or a start after the end of study?
Exercise 12-2. Add a second parameter, TTSAE: the time to the first treatment-emergent serious adverse event (AESER == "Y"), censored at the end of study. Use derive_param_tte(). How many events and censored subjects do you get?
Exercise 12-3. Count only the dermatologic events of the first 12 weeks: days 1 to 84, so the window ends at TRTSDT + 83. Build it by hand. A subject without an event in the window is censored at the end of study when the study ended inside the window, and at the end of the window otherwise. How many events do you get, and what happens to 01-705-1059?
Exercise 12-4. Join TRT01A from ADSL to your ADTTE. How many events does each arm have? Then use survfit() of the package survival for the Kaplan-Meier estimate. What is the median time to the first dermatologic event on each arm?
The answers are in Answers, Part II.
Found an error or have a question? Write to datastep.studio@gmail.com· Every program runs in DataStep Studio for R, the R extension for VS Code and Positron.
Data: the CDISC pilot study (cdiscpilot01), from the R packagespharmaversesdtm andpharmaverseadam (Apache License 2.0).
R is a project of the R Foundation. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. This book is not affiliated with or endorsed by SAS Institute Inc. or the R Foundation. CDISC, SDTM and ADaM are trademarks of the Clinical Data Interchange Standards Consortium.
© 2026 DataStep Labs. All rights reserved.