Review ask

As a clinical trial statistician or programmer, challenge anything in this benchmark: describe a problem in Comments, or propose a fix with the Edit button on any source file.

  1. Task: Would a real study need this derivation, specified this way? Does it follow CDISC ADaM: variable names, controlled terms, record structure? Flag any rule that is ambiguous or that a sponsor would handle differently.
  2. Inputs: Do they look like data collected in a real trial, and do they include the situations you would expect to meet in one?
  3. Expected output: Would independent QC programming reproduce every value from these inputs and rules?

The other tabs beside Comments are background for assessment, not under review.

Summary

Lifecycle: reviewedEditUnder review
What this benchmark means
README.md

Goal: build duration of response (DOR) records labeled Duration of Response, one for each responder, carrying STARTDT, ADT, AVAL, CNSR, EVNTDESC, CNSDTDSC, SRCDOM, SRCVAR and SRCSEQ.

Input: a subject-level table holding the response date (RESPDT) and the start date of a new anti-cancer therapy (NACTDT); response assessments holding the assessment date (ADT), the response (AVALC) and the record sequence number (ASEQ); and a disposition table holding the disposition term (DSDECOD), its date (DSSTDTC) and sequence number (DSSEQ). Only subjects whose RESPDT is not blank contribute a record.

Variables:

  • STARTDT is the response date, copied from the subject-level table.
  • ADT is the analysis date: the event date when a counted event exists, else the earlier of the last valid tumour assessment date and the therapy start date. The progression date is the earliest assessment date with a progressive disease (PD) response; the death date is the earliest disposition date with a DEATH term. The earlier of the two is the event date, unless it falls after the therapy start date; an event on the therapy-start day still counts. The last valid tumour assessment date is the latest assessment date carrying a response other than not evaluable (NE). An assessment with a blank date never counts as the progression date or the last valid assessment. When several records share the chosen date, the lowest sequence number is the progression record and the highest is the last valid assessment record.
  • AVAL is the number of days from STARTDT through ADT, counting both endpoints; it is at least 1.
  • CNSR is 0 when a counted event exists and 1 when the record is censored.
  • EVNTDESC names the outcome: CENSORED when no event counts; DISEASE PROGRESSION when the event date equals the progression date (so a same-day progression and death is reported as progression); DEATH otherwise.
  • CNSDTDSC is blank for an event; for a censored record it is LAST TUMOUR ASSESSMENT when censoring falls on the last valid tumour assessment date and START OF NEW ANTI-CANCER THERAPY otherwise.
  • SRCDOM traces ADT: ADRS for DISEASE PROGRESSION and for censoring at LAST TUMOUR ASSESSMENT, DS for DEATH, and ADSL for censoring at therapy start.
  • SRCVAR names the source field: DSSTDTC when SRCDOM is DS, ADT when SRCDOM is ADRS, and NACTDT otherwise.
  • SRCSEQ holds the source sequence number: the sequence number of the record chosen above (lowest on a progression tie, highest on a last-assessment tie, earliest death), and blank for censoring at therapy start.

Note: a new anti-cancer therapy closes observation: progression or death after the therapy start date never becomes the event, even when no valid assessment exists, and a record censored there traces to the subject-level therapy date with a blank sequence number.

Inputs

Under review
3 source files

input/adrs_raw.csv

Edit
29 rows
input/adrs_raw.csv
STUDYIDUSUBJIDASEQADTAVALC
YAMAA-0112025-02-17PR
YAMAA-0122025-04-07SD
YAMAA-0132025-05-19PD
YAMAA-0112025-01-20PR
YAMAA-0122025-03-24SD
YAMAA-0132025-06-02PD
YAMAA-0112025-02-03PR
YAMAA-0122025-03-10SD
YAMAA-0132025-04-21NE
YAMAA-0112025-03-03CR
YAMAA-0122025-05-05SD
YAMAA-0112025-03-17PR
YAMAA-0122025-05-05PD
YAMAA-0112025-02-24SD
YAMAA-0112025-04-01PR
YAMAA-0122025-06-10PD
YAMAA-0132025-06-10PD
YAMAA-0112025-01-06PR
YAMAA-0122025-03-01SD
YAMAA-0132025-05-01PD
YAMAA-0112025-02-04CR
YAMAA-0122025-06-10PD
YAMAA-0112025-02-10PR
YAMAA-0122025-04-01SD
YAMAA-013—SD
YAMAA-0112025-03-10NE
YAMAA-0112025-05-01PR
YAMAA-0122025-06-15SD
YAMAA-0132025-06-15SD

input/adsl.csv

Edit
12 rows
input/adsl.csv
STUDYIDUSUBJIDRESPDTNACTDT
YAMAA-012025-02-17—
YAMAA-012025-01-202025-04-14
YAMAA-012025-02-03—
YAMAA-012025-03-03—
YAMAA-012025-03-172025-05-05
YAMAA-01——
YAMAA-012025-04-01—
YAMAA-012025-01-06—
YAMAA-012025-02-04—
YAMAA-012025-02-10—
YAMAA-012025-03-012025-03-20
YAMAA-012025-05-01—

input/ds.csv

Edit
3 rows
input/ds.csv
STUDYIDUSUBJIDDSSEQDSDECODDSSTDTC
YAMAA-011DEATH2025-06-16
YAMAA-011DEATH2025-03-15
YAMAA-011DEATH2025-06-10

Expected output

Under review
11 expected rows

expected/adtte.csv

Edit
11 rows
expected/adtte.csv
STUDYIDUSUBJIDPARAMCDPARAMSTARTDTADTAVALCNSREVNTDESCCNSDTDSCSRCDOMSRCVARSRCSEQ
YAMAA-01DORDuration of Response2025-02-172025-05-19920DISEASE PROGRESSION—ADRSADT3
YAMAA-01DORDuration of Response2025-01-202025-04-14851CENSOREDSTART OF NEW ANTI-CANCER THERAPYADSLNACTDT—
YAMAA-01DORDuration of Response2025-02-032025-03-10361CENSOREDLAST TUMOUR ASSESSMENTADRSADT2
YAMAA-01DORDuration of Response2025-03-032025-06-161060DEATH—DSDSSTDTC1
YAMAA-01DORDuration of Response2025-03-172025-05-05500DISEASE PROGRESSION—ADRSADT2
YAMAA-01DORDuration of Response2025-04-012025-06-10710DISEASE PROGRESSION—ADRSADT2
YAMAA-01DORDuration of Response2025-01-062025-03-15690DEATH—DSDSSTDTC1
YAMAA-01DORDuration of Response2025-02-042025-06-101270DISEASE PROGRESSION—ADRSADT2
YAMAA-01DORDuration of Response2025-02-102025-04-01511CENSOREDLAST TUMOUR ASSESSMENTADRSADT2
YAMAA-01DORDuration of Response2025-03-012025-03-20201CENSOREDSTART OF NEW ANTI-CANCER THERAPYADSLNACTDT—
YAMAA-01DORDuration of Response2025-05-012025-06-15461CENSOREDLAST TUMOUR ASSESSMENTADRSADT3
Shaded columns are derived— = missing value

Comments and assessment materials

Comments

Signed in with GitHub; saved in repository Discussions

Mapping spec

Generated from the benchmark YAML; do not edit by hand

Dataset NameVariable NameVariable LabelTypeCodelist/Controlled TermsCoreComputational MethodOrigin
ADTTESTUDYIDStudy IdentifiercharacterCopy value from ADSL.STUDYID.Predecessor
ADTTEUSUBJIDUnique Subject IdentifiercharacterCopy value from ADSL.USUBJID.Predecessor
ADTTEPARAMCDParameter CodecharacterSet constant value "DOR".Assigned
ADTTEPARAMParametercharacterSet constant value "Duration of Response".Assigned
ADTTESTARTDTTime to Event Origin Date for SubjectnumericISO 8601Copy value from ADSL.RESPDT.Predecessor
ADTTECNSRCensornumericIf EVENTDT IS NOT NULL then "0"; otherwise "1".Derived
ADTTEEVNTDESCEvent or Censoring DescriptioncharacterIf EVENTDT IS NULL then "CENSORED"; If EVENTDT = PDDT then "DISEASE PROGRESSION"; otherwise "DEATH".Derived
ADTTEADTAnalysis DatenumericISO 8601First non-missing of EVENTDT and CENSORDT.Derived
ADTTEAVALAnalysis ValuenumericWhole days from STARTDT to ADT, counting both endpoints.Derived
ADTTECNSDTDSCCensoring Date DescriptioncharacterIf EVENTDT IS NOT NULL then "None"; If CENSORDT = LASTVLDT then "LAST TUMOUR ASSESSMENT"; otherwise "START OF NEW ANTI-CANCER THERAPY".Derived
ADTTESRCDOMSource DatacharacterIf EVNTDESC = 'DEATH' then "DS"; If EVNTDESC = 'DISEASE PROGRESSION' then "ADRS"; If CNSDTDSC = 'LAST TUMOUR ASSESSMENT' then "ADRS"; otherwise "ADSL".Derived
ADTTESRCVARSource VariablecharacterIf SRCDOM = 'DS' then "DSSTDTC"; If SRCDOM = 'ADRS' then "ADT"; otherwise "NACTDT".Derived
ADTTESRCSEQSource Sequence NumbernumericIf EVNTDESC = 'DISEASE PROGRESSION' then "PDSEQ"; If EVNTDESC = 'DEATH' then "DEATHSEQ"; If CNSDTDSC = 'LAST TUMOUR ASSESSMENT' then "LASTVLSEQ"; otherwise blank.Derived
VersionDateAuthorDescriptionReviewerSign-off
1.32026-09-29yamaa docs buildShow study codelist names, external dictionaries, and ISO 8601 formats in variable rows; list the document's codelist values and metadata
1.22026-09-29yamaa docs buildClassify ADaM copies from a declared input as Predecessor and recodes as Derived, and SDTM recodes of locally derived columns as Derived
1.12026-09-29yamaa docs buildResolve lookups into the donor record they select, and give every derivation shape a plain-language rule instead of its raw YAML
1.0yamaa docs buildInitial generation from spec.yaml

Agent prompt

The request an agent receives with the input files; each tier states no more than the one above

prompts/adam-adtte-dor/full.md

Edit
44 lines

Following CDISC ADaM standards, use the provided ADSL, ADRS_RAW, and DS datasets to create an ADTTE dataset for duration of response, with one record per responder. A responder is a subject with a response date (RESPDT) in ADSL.

The output dataset should contain the following columns in this order: STUDYID, USUBJID, PARAMCD, PARAM, STARTDT, ADT, AVAL, CNSR, EVNTDESC, CNSDTDSC, SRCDOM, SRCVAR, SRCSEQ

Use PARAMCD "DOR" and PARAM "Duration of Response". STARTDT is the response date.

The event is disease progression (the earliest assessment with a PD response) or death (the earliest DS record with a DEATH term), whichever comes first. An event counts only when it falls on or before the start of new anti-cancer therapy (NACTDT in ADSL).

A responder without a counted event is censored at the earlier of the last evaluable tumour assessment and the start of new anti-cancer therapy. An evaluable assessment has a date and a response other than NE, whether it falls before or after the start of new therapy.

ADT is the event or censoring date. AVAL is the number of days from STARTDT to ADT, counting both days. CNSR is 0 for an event and 1 for a censored record.

Describe each record with these values:

  • EVNTDESC is DISEASE PROGRESSION, DEATH, or CENSORED. When progression and death fall on the same day, report DISEASE PROGRESSION.
  • CNSDTDSC is LAST TUMOUR ASSESSMENT or START OF NEW ANTI-CANCER THERAPY for a censored record, and has no value for an event.

Identify the source of ADT with SRCDOM, SRCVAR, and SRCSEQ:

  • progression, or censoring at the last tumour assessment: ADRS, ADT, and the assessment's ASEQ;
  • death: DS, DSSTDTC, and DSSEQ;
  • censoring at the start of new therapy: ADSL, NACTDT, and no sequence.

When several records share the selected date, use the lowest sequence number for progression or death and the highest for the last tumour assessment.

Read the source datasets from /app/input and save the completed dataset as /app/output/adtte.csv.

prompts/adam-adtte-dor/conventions.md

Edit
18 lines

Following CDISC ADaM standards, use the provided ADSL, ADRS_RAW, and DS datasets to create an ADTTE dataset for duration of response, with one record per responder. A responder is a subject with a response date (RESPDT) in ADSL.

The output dataset should contain the following columns in this order: STUDYID, USUBJID, PARAMCD, PARAM, STARTDT, ADT, AVAL, CNSR, EVNTDESC, CNSDTDSC, SRCDOM, SRCVAR, SRCSEQ

PARAMCD is "DOR" and PARAM "Duration of Response". AVAL counts both STARTDT and ADT. CNSR is 0 for an event and 1 for a censored record. EVNTDESC is DISEASE PROGRESSION, DEATH, or CENSORED; CNSDTDSC is LAST TUMOUR ASSESSMENT, START OF NEW ANTI-CANCER THERAPY, or has no value. SRCDOM, SRCVAR, and SRCSEQ are ADRS, ADT, and the assessment's ASEQ; DS, DSSTDTC, and DSSEQ; or ADSL, NACTDT, and no sequence.

Read the source datasets from /app/input and save the completed dataset as /app/output/adtte.csv.

prompts/adam-adtte-dor/brief.md

Edit
11 lines

Following CDISC ADaM standards, use the provided ADSL, ADRS_RAW, and DS datasets to create an ADTTE dataset for duration of response, with one record per responder. A responder is a subject with a response date (RESPDT) in ADSL.

The output dataset should contain the following columns in this order: STUDYID, USUBJID, PARAMCD, PARAM, STARTDT, ADT, AVAL, CNSR, EVNTDESC, CNSDTDSC, SRCDOM, SRCVAR, SRCSEQ

Read the source datasets from /app/input and save the completed dataset as /app/output/adtte.csv.

yamaa code

Runs the yamaa specification; its result must match the expected output

run.R

Edit
4 lines
library(yamaa)adtte <- yamaa_domain("spec.yaml")$outputadtte

run.py

Edit
4 lines
import yamaaadtte = yamaa.yamaa_domain("spec.yaml").outputadtte

Solution without yamaa

Written from the full prompt and the inputs alone; CI checks it reproduces the expected output

solutions/adam-adtte-dor/result.R

Edit
100 lines
# Reference solution for the yamaa benchmark adam-adtte-dor (R track).## Written from the benchmark's full prompt and its inputs alone, as an agent# would write it. Harbor's oracle agent runs it to check that the prompt can# be solved and that the grader scores a correct answer 1.library(dplyr, warn.conflicts = FALSE)library(readr)adsl <- read_csv(  "/app/input/adsl.csv",  col_types = cols(RESPDT = col_date(), NACTDT = col_date(), .default = col_character()))adrs <- read_csv(  "/app/input/adrs_raw.csv",  col_types = cols(ASEQ = col_integer(), ADT = col_date(), .default = col_character()))ds <- read_csv(  "/app/input/ds.csv",  col_types = cols(DSSEQ = col_integer(), DSSTDTC = col_date(), .default = col_character()))# Earliest progression and death, lowest sequence number on a tie.progression <- adrs |>  filter(AVALC %in% "PD", !is.na(ADT)) |>  arrange(USUBJID, ADT, ASEQ) |>  distinct(USUBJID, .keep_all = TRUE) |>  select(USUBJID, PDDT = ADT, PDSEQ = ASEQ)death <- ds |>  filter(DSDECOD %in% "DEATH", !is.na(DSSTDTC)) |>  arrange(USUBJID, DSSTDTC, DSSEQ) |>  distinct(USUBJID, .keep_all = TRUE) |>  select(USUBJID, DTHDT = DSSTDTC, DTHSEQ = DSSEQ)# Last evaluable assessment (a date and a response other than NE), highest# sequence number on a tie.last_assessment <- adrs |>  filter(!is.na(ADT), !is.na(AVALC), AVALC != "NE") |>  arrange(USUBJID, desc(ADT), desc(ASEQ)) |>  distinct(USUBJID, .keep_all = TRUE) |>  select(USUBJID, LASTDT = ADT, LASTSEQ = ASEQ)# Where ADT comes from, for each outcome.sources <- tribble(  ~OUTCOME,                           ~SRCDOM, ~SRCVAR,  "DISEASE PROGRESSION",              "ADRS",  "ADT",  "DEATH",                            "DS",    "DSSTDTC",  "LAST TUMOUR ASSESSMENT",           "ADRS",  "ADT",  "START OF NEW ANTI-CANCER THERAPY", "ADSL",  "NACTDT")adtte <- adsl |>  filter(!is.na(RESPDT)) |>  left_join(progression, by = "USUBJID") |>  left_join(death, by = "USUBJID") |>  left_join(last_assessment, by = "USUBJID") |>  mutate(    # The first event; progression wins a same-day tie with death.    EVENT = case_when(      !is.na(PDDT) & (is.na(DTHDT) | PDDT <= DTHDT) ~ "DISEASE PROGRESSION",      !is.na(DTHDT) ~ "DEATH"    ),    EVENTDT = if_else(EVENT == "DEATH", DTHDT, PDDT),    # An event after the start of new therapy does not count.    EVENT = if_else(!is.na(NACTDT) & EVENTDT > NACTDT, NA_character_, EVENT),    # Without a counted event, the record is censored at the earlier of the    # last evaluable assessment and the start of new therapy.    OUTCOME = case_when(      !is.na(EVENT) ~ EVENT,      !is.na(LASTDT) & (is.na(NACTDT) | LASTDT <= NACTDT) ~ "LAST TUMOUR ASSESSMENT",      !is.na(NACTDT) ~ "START OF NEW ANTI-CANCER THERAPY"    ),    ADT = case_when(      OUTCOME == "DISEASE PROGRESSION" ~ PDDT,      OUTCOME == "DEATH" ~ DTHDT,      OUTCOME == "LAST TUMOUR ASSESSMENT" ~ LASTDT,      OUTCOME == "START OF NEW ANTI-CANCER THERAPY" ~ NACTDT    ),    SRCSEQ = case_when(      OUTCOME == "DISEASE PROGRESSION" ~ PDSEQ,      OUTCOME == "DEATH" ~ DTHSEQ,      OUTCOME == "LAST TUMOUR ASSESSMENT" ~ LASTSEQ    ),    PARAMCD = "DOR",    PARAM = "Duration of Response",    STARTDT = RESPDT,    AVAL = as.integer(ADT - STARTDT) + 1L,    CNSR = if_else(is.na(EVENT), 1L, 0L),    EVNTDESC = coalesce(EVENT, "CENSORED"),    CNSDTDSC = if_else(is.na(EVENT), OUTCOME, NA_character_)  ) |>  left_join(sources, by = "OUTCOME") |>  select(    STUDYID, USUBJID, PARAMCD, PARAM, STARTDT, ADT, AVAL, CNSR, EVNTDESC,    CNSDTDSC, SRCDOM, SRCVAR, SRCSEQ  )dir.create("/app/output", showWarnings = FALSE)write_csv(adtte, "/app/output/adtte.csv", na = "")

solutions/adam-adtte-dor/result.py

Edit
141 lines
# Reference solution for the yamaa benchmark adam-adtte-dor (Python track).## Written from the benchmark's full prompt and its inputs alone, as an agent# would write it. Harbor's oracle agent runs it to check that the prompt can# be solved and that the grader scores a correct answer 1.from pathlib import Pathimport polars as pldef read(name: str) -> pl.DataFrame:    return pl.read_csv(f"/app/input/{name}", infer_schema=False)def first_per_subject(    records: pl.DataFrame, by: list[str], descending: bool = False) -> pl.DataFrame:    return records.sort(by, descending=descending).unique(        "USUBJID", keep="first", maintain_order=True    )adsl = read("adsl.csv").with_columns(pl.col("RESPDT", "NACTDT").str.to_date())adrs = read("adrs_raw.csv").with_columns(    pl.col("ADT").str.to_date(), pl.col("ASEQ").cast(pl.Int64))ds = read("ds.csv").with_columns(    pl.col("DSSTDTC").str.to_date(), pl.col("DSSEQ").cast(pl.Int64))# Earliest progression and death, lowest sequence number on a tie.progression = first_per_subject(    adrs.filter(pl.col("AVALC") == "PD", pl.col("ADT").is_not_null()),    ["ADT", "ASEQ"],).select("USUBJID", PDDT="ADT", PDSEQ="ASEQ")death = first_per_subject(    ds.filter(pl.col("DSDECOD") == "DEATH", pl.col("DSSTDTC").is_not_null()),    ["DSSTDTC", "DSSEQ"],).select("USUBJID", DTHDT="DSSTDTC", DTHSEQ="DSSEQ")# Last evaluable assessment (a date and a response other than NE), highest# sequence number on a tie.last_assessment = first_per_subject(    adrs.filter(pl.col("ADT").is_not_null(), pl.col("AVALC") != "NE"),    ["ADT", "ASEQ"],    descending=True,).select("USUBJID", LASTDT="ADT", LASTSEQ="ASEQ")# Where ADT comes from, for each outcome.sources = pl.DataFrame(    {        "OUTCOME": [            "DISEASE PROGRESSION",            "DEATH",            "LAST TUMOUR ASSESSMENT",            "START OF NEW ANTI-CANCER THERAPY",        ],        "SRCDOM": ["ADRS", "DS", "ADRS", "ADSL"],        "SRCVAR": ["ADT", "DSSTDTC", "ADT", "NACTDT"],    })PDDT, DTHDT, LASTDT, NACTDT = (    pl.col(name) for name in ("PDDT", "DTHDT", "LASTDT", "NACTDT"))EVENT, OUTCOME = pl.col("EVENT"), pl.col("OUTCOME")adtte = (    adsl.filter(pl.col("RESPDT").is_not_null())    .join(progression, on="USUBJID", how="left")    .join(death, on="USUBJID", how="left")    .join(last_assessment, on="USUBJID", how="left")    # The first event; progression wins a same-day tie with death.    .with_columns(        EVENT=pl.when(PDDT.is_not_null() & (DTHDT.is_null() | (PDDT <= DTHDT)))        .then(pl.lit("DISEASE PROGRESSION"))        .when(DTHDT.is_not_null())        .then(pl.lit("DEATH"))    )    .with_columns(EVENTDT=pl.when(EVENT == "DEATH").then(DTHDT).otherwise(PDDT))    # An event after the start of new therapy does not count.    .with_columns(        EVENT=pl.when(NACTDT.is_not_null() & (pl.col("EVENTDT") > NACTDT))        .then(None)        .otherwise(EVENT)    )    # Without a counted event, the record is censored at the earlier of the    # last evaluable assessment and the start of new therapy.    .with_columns(        OUTCOME=pl.when(EVENT.is_not_null())        .then(EVENT)        .when(LASTDT.is_not_null() & (NACTDT.is_null() | (LASTDT <= NACTDT)))        .then(pl.lit("LAST TUMOUR ASSESSMENT"))        .when(NACTDT.is_not_null())        .then(pl.lit("START OF NEW ANTI-CANCER THERAPY"))    )    .with_columns(        ADT=pl.when(OUTCOME == "DISEASE PROGRESSION")        .then(PDDT)        .when(OUTCOME == "DEATH")        .then(DTHDT)        .when(OUTCOME == "LAST TUMOUR ASSESSMENT")        .then(LASTDT)        .when(OUTCOME == "START OF NEW ANTI-CANCER THERAPY")        .then(NACTDT),        SRCSEQ=pl.when(OUTCOME == "DISEASE PROGRESSION")        .then(pl.col("PDSEQ"))        .when(OUTCOME == "DEATH")        .then(pl.col("DTHSEQ"))        .when(OUTCOME == "LAST TUMOUR ASSESSMENT")        .then(pl.col("LASTSEQ")),        PARAMCD=pl.lit("DOR"),        PARAM=pl.lit("Duration of Response"),        STARTDT=pl.col("RESPDT"),        CNSR=pl.when(EVENT.is_null()).then(1).otherwise(0),        EVNTDESC=pl.coalesce(EVENT, pl.lit("CENSORED")),        CNSDTDSC=pl.when(EVENT.is_null()).then(OUTCOME),    )    .with_columns(AVAL=(pl.col("ADT") - pl.col("STARTDT")).dt.total_days() + 1)    .join(sources, on="OUTCOME", how="left")    .select(        "STUDYID",        "USUBJID",        "PARAMCD",        "PARAM",        "STARTDT",        "ADT",        "AVAL",        "CNSR",        "EVNTDESC",        "CNSDTDSC",        "SRCDOM",        "SRCVAR",        "SRCSEQ",    ))Path("/app/output").mkdir(exist_ok=True)adtte.write_csv("/app/output/adtte.csv")

solutions/adam-adtte-dor/result.sas

Edit
53 lines
/* opensas reference solution for the yamaa benchmark adam-adtte-dor.   Reads the benchmark inputs and derives the requested output.   Execute with the existing opensas runtime: opensas /app/output/result.sas. */data adrs_raw;  length STUDYID USUBJID ADT AVALC $1024;  infile "/app/input/adrs_raw.csv" dsd dlm="," firstobs=2 truncover lrecl=32767;  input STUDYID : $char1024. USUBJID : $char1024. ASEQ ADT : $char1024. AVALC : $char1024.;run;data adsl;  length STUDYID USUBJID RESPDT NACTDT $1024;  infile "/app/input/adsl.csv" dsd dlm="," firstobs=2 truncover lrecl=32767;  input STUDYID : $char1024. USUBJID : $char1024. RESPDT : $char1024. NACTDT : $char1024.;run;data ds;  length STUDYID USUBJID DSDECOD DSSTDTC $1024;  infile "/app/input/ds.csv" dsd dlm="," firstobs=2 truncover lrecl=32767;  input STUDYID : $char1024. USUBJID : $char1024. DSSEQ DSDECOD : $char1024. DSSTDTC : $char1024.;run;proc sql;  create table usable as select a.* from adrs_raw as a inner join adsl as b on a.STUDYID=b.STUDYID and a.USUBJID=b.USUBJID where a.ADT ne '' and a.AVALC ne 'NE';  create table progression as select a.* from adrs_raw as a inner join adsl as b on a.STUDYID=b.STUDYID and a.USUBJID=b.USUBJID where a.ADT ne '' and a.AVALC='PD' and a.AVALC ne 'NE' and (missing(b.NACTDT) or a.ADT<=b.NACTDT);  create table deaths as select a.* from ds as a inner join adsl as b on a.STUDYID=b.STUDYID and a.USUBJID=b.USUBJID where a.DSDECOD='DEATH' and a.DSSTDTC ne '' and (missing(b.NACTDT) or a.DSSTDTC<=b.NACTDT);quit;proc sort data=progression; by STUDYID USUBJID ADT ASEQ; run;data pd; set progression; by STUDYID USUBJID; if first.USUBJID; keep STUDYID USUBJID ADT ASEQ; rename ADT=PDDT ASEQ=PDSEQ; run;proc sort data=deaths; by STUDYID USUBJID DSSTDTC DSSEQ; run;data death; set deaths; by STUDYID USUBJID; if first.USUBJID; keep STUDYID USUBJID DSSTDTC DSSEQ; rename DSSTDTC=DEATHDT DSSEQ=DEATHSEQ; run;proc sort data=usable; by STUDYID USUBJID descending ADT descending ASEQ; run;data lastassessment; set usable; by STUDYID USUBJID; if first.USUBJID; keep STUDYID USUBJID ADT ASEQ; rename ADT=LASTDT ASEQ=LASTSEQ; run;proc sql; create table joined as select a.*,b.PDDT,b.PDSEQ,c.DEATHDT,c.DEATHSEQ,d.LASTDT,d.LASTSEQ from adsl as a  left join pd as b on a.STUDYID=b.STUDYID and a.USUBJID=b.USUBJID left join death as c on a.STUDYID=c.STUDYID and a.USUBJID=c.USUBJID left join lastassessment as d on a.STUDYID=d.STUDYID and a.USUBJID=d.USUBJID; quit;data result;  length PARAMCD $8 PARAM $40 STARTDT ADT $10 EVNTDESC CNSDTDSC $40 SRCDOM $4 SRCVAR $16;  set joined; if not missing(RESPDT);  PARAMCD='DOR'; PARAM='Duration of Response'; STARTDT=RESPDT;  if not missing(PDDT) and (missing(DEATHDT) or PDDT<=DEATHDT) then do; ADT=PDDT; CNSR=0; EVNTDESC='DISEASE PROGRESSION'; SRCDOM='ADRS'; SRCVAR='ADT'; SRCSEQ=PDSEQ; end;  else if not missing(DEATHDT) then do; ADT=DEATHDT; CNSR=0; EVNTDESC='DEATH'; SRCDOM='DS'; SRCVAR='DSSTDTC'; SRCSEQ=DEATHSEQ; end;  else do;    CNSR=1; EVNTDESC='CENSORED';    if not missing(NACTDT) and (missing(LASTDT) or NACTDT<LASTDT) then do; ADT=NACTDT; CNSDTDSC='START OF NEW ANTI-CANCER THERAPY'; SRCDOM='ADSL'; SRCVAR='NACTDT'; end;    else do; ADT=LASTDT; CNSDTDSC='LAST TUMOUR ASSESSMENT'; SRCDOM='ADRS'; SRCVAR='ADT'; SRCSEQ=LASTSEQ; end;  end;  if not missing(ADT) and not missing(STARTDT) then AVAL=input(ADT,yymmdd10.)-input(STARTDT,yymmdd10.)+1;run;proc sql;  create table final as select STUDYID, USUBJID, PARAMCD, PARAM, STARTDT, ADT, AVAL, CNSR, EVNTDESC, CNSDTDSC, SRCDOM, SRCVAR, SRCSEQ from result;quit;proc export data=final outfile="/app/output/adtte.csv" dbms=csv replace; run;