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.
- 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.
- Inputs: Do they look like data collected in a real trial, and do they include the situations you would expect to meet in one?
- 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
README.mdGoal: one row per adverse event (AE), marking treatment
emergence (TRTEMFL) and the subject's earliest treatment-emergent
event (AOCCFL) from onset, first exposure, and the study's
30-day post-last-exposure emergence window.
Input: adverse event records carrying the reported term
(AETERM) and the collected onset moment (ASTDTM, empty when never
collected), plus the moments of first and last exposure (TRTSDTM,
TRTENDTM) from the subject-level analysis dataset (ADSL); the
emergence window end (TEENDDTM, last exposure plus 30 days) is
carried alongside. An untreated subject appears in ADSL with an empty
TRTSDTM and none of their events get flagged.
Variables:
TEENDDTMis the end of the treatment-emergent window: 30 days after last exposure.TRTEMFLholdsYwhen the event started inside the window - at or after first exposure and at or before the window end. It stays empty for an earlier or later event. A missing onset cannot be ruled pre-treatment, so the conservative convention flags itYwhenever the subject was treated; an untreated subject's events stay empty.AOCCFLholdsYon the subject's earliest treatment-emergent event, ordered by onset moment with the lower sequence number (AESEQ) settling ties at the same second. All other rows stay empty; a treatment-emergent event with a missing onset is flagged but cannot be ordered, so it never carries the occurrence flag.
Note: emergence is decided at the moment, not the day: an event that started earlier on the day of first exposure and one that started later that same day fall on opposite sides, and a start date alone cannot tell them apart.
Note: a collected datetime without seconds is coerced to the
second (seconds zero-filled) and compared at second precision.
HEADACHE is collected as 2025-03-04T11:45 and VOMITING as
2025-03-04T11:45:00; both land on the same second, so the
AOCCFL tie-break ("the lower sequence number settles ties at
the same second") is what picks the earliest treatment-emergent
event. No time-imputation flag is derived for the coerced value:
the coercion happens inside the engine's datetime type, and the
language's collected-precision model reports only day/second
tiers, so a minute-precision source is not distinguishable from
a second-precision one in spec language.
Inputs
Under review2 source filesinput/adsl.csv
Edit3 rows| STUDYID | USUBJID | TRTSDTM | TRTENDTM | TEENDDTM |
|---|---|---|---|---|
| PILOT7 | 2025-03-04T09:00:00 | 2025-03-10T09:00:00 | 2025-04-09T09:00:00 | |
| PILOT7 | 2025-03-05T09:00:00 | 2025-03-05T09:00:00 | 2025-04-04T09:00:00 | |
| PILOT7 | — | — | — |
input/ae.csv
Edit10 rows| STUDYID | USUBJID | AESEQ | AETERM | AESTDTC |
|---|---|---|---|---|
| PILOT7 | 1 | CHILLS | 2025-03-04T07:15:00 | |
| PILOT7 | 2 | HEADACHE | 2025-03-04T11:45 | |
| PILOT7 | 3 | NAUSEA | 2025-03-06T22:30:00 | |
| PILOT7 | 4 | VOMITING | 2025-03-04T11:45:00 | |
| PILOT7 | 5 | BACK PAIN | 2025-04-15T10:00:00 | |
| PILOT7 | 6 | COUGH | 2025-03-20T08:00:00 | |
| PILOT7 | 1 | RASH | 2025-03-05T09:00:00 | |
| PILOT7 | 2 | PRURITUS | — | |
| PILOT7 | 3 | DIZZINESS | 2025-04-04T09:00 | |
| PILOT7 | 1 | FATIGUE | 2025-03-07T13:05:00 |
Expected output
Under review10 expected rowsexpected/adae.csv
Edit10 rows| STUDYID | USUBJID | AESEQ | AETERM | ASTDTM | TRTSDTM | TEENDDTM | TRTEMFL | AOCCFL |
|---|---|---|---|---|---|---|---|---|
| PILOT7 | 1 | CHILLS | 2025-03-04T07:15:00 | 2025-03-04T09:00:00 | 2025-04-09T09:00:00 | — | — | |
| PILOT7 | 2 | HEADACHE | 2025-03-04T11:45:00 | 2025-03-04T09:00:00 | 2025-04-09T09:00:00 | Y | Y | |
| PILOT7 | 3 | NAUSEA | 2025-03-06T22:30:00 | 2025-03-04T09:00:00 | 2025-04-09T09:00:00 | Y | — | |
| PILOT7 | 4 | VOMITING | 2025-03-04T11:45:00 | 2025-03-04T09:00:00 | 2025-04-09T09:00:00 | Y | — | |
| PILOT7 | 5 | BACK PAIN | 2025-04-15T10:00:00 | 2025-03-04T09:00:00 | 2025-04-09T09:00:00 | — | — | |
| PILOT7 | 6 | COUGH | 2025-03-20T08:00:00 | 2025-03-04T09:00:00 | 2025-04-09T09:00:00 | Y | — | |
| PILOT7 | 1 | RASH | 2025-03-05T09:00:00 | 2025-03-05T09:00:00 | 2025-04-04T09:00:00 | Y | Y | |
| PILOT7 | 2 | PRURITUS | — | 2025-03-05T09:00:00 | 2025-04-04T09:00:00 | Y | — | |
| PILOT7 | 3 | DIZZINESS | 2025-04-04T09:00:00 | 2025-03-05T09:00:00 | 2025-04-04T09:00:00 | Y | — | |
| PILOT7 | 1 | FATIGUE | 2025-03-07T13:05:00 | — | — | — | — |
Comments and assessment materials
| Dataset Name | Variable Name | Variable Label | Type | Codelist/Controlled Terms | Core | Computational Method | Origin |
|---|---|---|---|---|---|---|---|
| ADAE | STUDYID | Study Identifier | character | Copy value from AE.STUDYID. | Predecessor | ||
| ADAE | USUBJID | Unique Subject Identifier | character | Copy value from AE.USUBJID. | Predecessor | ||
| ADAE | AESEQ | Sequence Number | numeric | Copy value from AE.AESEQ. | Predecessor | ||
| ADAE | AETERM | Reported Term for the Adverse Event | character | Copy value from AE.AETERM. | Predecessor | ||
| ADAE | ASTDTM | Analysis Start Date/Time | numeric | ISO 8601 | Copy value from AE.AESTDTC. | Predecessor | |
| ADAE | TRTSDTM | Datetime of First Exposure to Treatment | numeric | ISO 8601 | Copy value from ADSL.TRTSDTM. | Predecessor | |
| ADAE | TEENDDTM | End of Treatment-Emergent Window | numeric | ISO 8601 | Copy value from ADSL.TEENDDTM. | Predecessor | |
| ADAE | TRTEMFL | Treatment Emergent Analysis Flag | character | Y | If TRTSDTM IS NULL then "None"; If ASTDTM IS NULL then "Y"; If ASTDTM >= TRTSDTM AND ASTDTM <= TEENDDTM then "Y"; otherwise "None". | Derived | |
| ADAE | AOCCFL | First Occurrence Within Subject Flag | character | Y | "Y" when AOCCSEQ = 1; blank otherwise. | Derived |
| Variable | Permitted values |
|---|---|
| TRTEMFL | Y |
| AOCCFL | Y |
| Version | Date | Author | Description | Reviewer | Sign-off |
|---|---|---|---|---|---|
| 1.3 | 2026-09-29 | yamaa docs build | Show study codelist names, external dictionaries, and ISO 8601 formats in variable rows; list the document's codelist values and metadata | ||
| 1.2 | 2026-09-29 | yamaa docs build | Classify ADaM copies from a declared input as Predecessor and recodes as Derived, and SDTM recodes of locally derived columns as Derived | ||
| 1.1 | 2026-09-29 | yamaa docs build | Resolve lookups into the donor record they select, and give every derivation shape a plain-language rule instead of its raw YAML | ||
| 1.0 | yamaa docs build | Initial generation from spec.yaml |
prompts/adam-adae-onset-emergence/full.md
Edit27 linesFollowing CDISC ADaM standards, use the provided AE and ADSL datasets to create an ADAE dataset with one record per adverse event.
The output dataset should contain the following columns in this order: STUDYID, USUBJID, AESEQ, AETERM, ASTDTM, TRTSDTM, TEENDDTM, TRTEMFL, AOCCFL
ASTDTM is the collected onset moment, TRTSDTM is the moment of first exposure from ADSL, and TEENDDTM is the end of the treatment-emergent window (30 days after last exposure) from ADSL.
TRTEMFL is Y when the event started inside the window from first exposure through the window end, inclusive. It has no value for an event that started before first exposure or after the window end. A missing onset cannot be ruled pre-treatment, so a treated subject's event with a missing onset is flagged Y; a subject with no first exposure at all is never treatment-emergent. Emergence is decided at the moment, not the day: events starting earlier and later on the day of first exposure fall on opposite sides.
AOCCFL is Y on the subject's earliest treatment-emergent event with a known onset, ordered by onset moment with the lower AESEQ settling ties at the same second. Events with missing onset are excluded from this selection. All other rows have no value.
Read the source datasets from /app/input and save the completed dataset as /app/output/adae.csv.
prompts/adam-adae-onset-emergence/conventions.md
Edit11 linesFollowing CDISC ADaM standards, use the provided AE and ADSL datasets to create an ADAE dataset with one record per adverse event.
The output dataset should contain the following columns in this order: STUDYID, USUBJID, AESEQ, AETERM, ASTDTM, TRTSDTM, TEENDDTM, TRTEMFL, AOCCFL
TRTEMFL is Y or has no value. AOCCFL is Y or has no value.
Read the source datasets from /app/input and save the completed dataset as /app/output/adae.csv.
prompts/adam-adae-onset-emergence/brief.md
Edit9 linesFollowing CDISC ADaM standards, use the provided AE and ADSL datasets to create an ADAE dataset with one record per adverse event.
The output dataset should contain the following columns in this order: STUDYID, USUBJID, AESEQ, AETERM, ASTDTM, TRTSDTM, TEENDDTM, TRTEMFL, AOCCFL
Read the source datasets from /app/input and save the completed dataset as /app/output/adae.csv.
run.R
Edit4 lineslibrary(yamaa)adae <- yamaa_domain("spec.yaml")$outputadaerun.py
Edit4 linesimport yamaaadae = yamaa.yamaa_domain("spec.yaml").outputadaesolutions/adam-adae-onset-emergence/result.R
Edit73 lines# Reference solution for the yamaa benchmark adam-adae-onset-emergence (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)library(stringr)ae <- read_csv( "/app/input/ae.csv", col_types = cols(AESEQ = col_integer(), .default = col_character()))adsl <- read_csv( "/app/input/adsl.csv", col_types = cols(.default = col_character()))# Datetimes collected without seconds are completed to the second so the# onset and the first exposure compare at the moment, not the day.complete_seconds <- function(x) { if_else( !is.na(x) & str_detect(x, "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}$"), paste0(x, ":00"), x )}ae <- ae |> mutate(ASTDTM = complete_seconds(AESTDTC)) |> select(STUDYID, USUBJID, AESEQ, AETERM, ASTDTM)adsl <- adsl |> mutate(TRTSDTM = complete_seconds(TRTSDTM), TEENDDTM = complete_seconds(TEENDDTM)) |> select(USUBJID, TRTSDTM, TEENDDTM)# The window rule: onset inside [first exposure, window end] is# treatment-emergent. A missing onset cannot be ruled pre-treatment,# so a treated subject's event with a missing onset is flagged Y; an# untreated subject (no first exposure) is never treatment-emergent.adae <- ae |> left_join(adsl, by = "USUBJID") |> mutate( TRTEMFL = case_when( is.na(TRTSDTM) ~ NA_character_, is.na(ASTDTM) ~ "Y", ASTDTM >= TRTSDTM & ASTDTM <= TEENDDTM ~ "Y", .default = NA_character_ ) )# The subject's earliest treatment-emergent event with a known onset,# ordered by onset moment with the lower AESEQ settling ties at the# same second.first <- adae |> filter(TRTEMFL %in% "Y", !is.na(ASTDTM)) |> arrange(USUBJID, ASTDTM, AESEQ) |> distinct(USUBJID, .keep_all = TRUE) |> select(USUBJID, FIRST_SEQ = AESEQ)adae <- adae |> left_join(first, by = "USUBJID") |> mutate( AOCCFL = if_else(!is.na(FIRST_SEQ) & AESEQ == FIRST_SEQ, "Y", NA_character_) ) |> select( STUDYID, USUBJID, AESEQ, AETERM, ASTDTM, TRTSDTM, TEENDDTM, TRTEMFL, AOCCFL )dir.create("/app/output", showWarnings = FALSE)write_csv(adae, "/app/output/adae.csv", na = "")solutions/adam-adae-onset-emergence/result.py
Edit87 lines# Reference solution for the yamaa benchmark adam-adae-onset-emergence (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 plae = pl.read_csv("/app/input/ae.csv", infer_schema=False).with_columns( pl.col("AESEQ").cast(pl.Int64))adsl = pl.read_csv("/app/input/adsl.csv", infer_schema=False)def complete_seconds(frame: pl.DataFrame, name: str, out: str) -> pl.DataFrame: # Datetimes collected without seconds are completed to the second so # the onset and the first exposure compare at the moment, not the day. return frame.with_columns( pl.when(pl.col(name).str.contains(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$")) .then(pl.col(name) + ":00") .otherwise(pl.col(name)) .alias(out) )ae = complete_seconds(ae, "AESTDTC", "ASTDTM").select( "STUDYID", "USUBJID", "AESEQ", "AETERM", "ASTDTM")adsl = ( complete_seconds(adsl, "TRTSDTM", "TRTSDTM") .pipe(complete_seconds, "TEENDDTM", "TEENDDTM") .select("USUBJID", "TRTSDTM", "TEENDDTM"))# The window rule: onset inside [first exposure, window end] is# treatment-emergent. A missing onset cannot be ruled pre-treatment,# so a treated subject's event with a missing onset is flagged Y; an# untreated subject (no first exposure) is never treatment-emergent.adae = ae.join(adsl, on="USUBJID", how="left", maintain_order="left").with_columns( TRTEMFL=pl.when(pl.col("TRTSDTM").is_null()) .then(None) .when(pl.col("ASTDTM").is_null()) .then(pl.lit("Y")) .when( (pl.col("ASTDTM") >= pl.col("TRTSDTM")) & (pl.col("ASTDTM") <= pl.col("TEENDDTM")) ) .then(pl.lit("Y")) .otherwise(None))# The subject's earliest treatment-emergent event with a known onset,# ordered by onset moment with the lower AESEQ settling ties at the# same second. ISO datetimes sort as text once seconds are completed.first = ( adae.filter( (pl.col("TRTEMFL") == "Y") & pl.col("ASTDTM").is_not_null() ) .sort(["USUBJID", "ASTDTM", "AESEQ"], nulls_last=True) .unique("USUBJID", keep="first", maintain_order=True) .select("USUBJID", FIRST_SEQ="AESEQ"))adae = ( adae.join(first, on="USUBJID", how="left") .with_columns( AOCCFL=pl.when( pl.col("FIRST_SEQ").is_not_null() & (pl.col("AESEQ") == pl.col("FIRST_SEQ")) ).then(pl.lit("Y")) ) .select( "STUDYID", "USUBJID", "AESEQ", "AETERM", "ASTDTM", "TRTSDTM", "TEENDDTM", "TRTEMFL", "AOCCFL", ))Path("/app/output").mkdir(exist_ok=True)adae.write_csv("/app/output/adae.csv")solutions/adam-adae-onset-emergence/result.sas
Edit41 lines/* opensas reference solution for the yamaa benchmark adam-adae-onset-emergence. Reads the benchmark inputs and derives the requested output. Execute with the existing opensas runtime: opensas /app/output/result.sas. */data adsl; length STUDYID USUBJID TRTSDTM TRTENDTM TEENDDTM $1024; infile "/app/input/adsl.csv" dsd dlm="," firstobs=2 truncover lrecl=32767; input STUDYID : $char1024. USUBJID : $char1024. TRTSDTM : $char1024. TRTENDTM : $char1024. TEENDDTM : $char1024.;run;data ae; length STUDYID USUBJID AETERM AESTDTC $1024; infile "/app/input/ae.csv" dsd dlm="," firstobs=2 truncover lrecl=32767; input STUDYID : $char1024. USUBJID : $char1024. AESEQ AETERM : $char1024. AESTDTC : $char1024.;run;proc sql; create table joined as select a.*,b.TRTSDTM,b.TEENDDTM from ae as a left join adsl as b on a.STUDYID=b.STUDYID and a.USUBJID=b.USUBJID; quit;data events; length ASTDTM $19 TRTEMFL $1; set joined; ASTDTM=''; TRTEMFL=''; /* Datetimes collected without seconds are completed to the second so the onset and the first exposure compare at the moment, not the day. */ if not missing(AESTDTC) then ASTDTM=cats(AESTDTC,ifc(lengthn(AESTDTC)=16,':00','')); onset=input(ASTDTM,e8601dt.); treatment=input(TRTSDTM,e8601dt.); window_end=input(TEENDDTM,e8601dt.); /* The window rule: onset inside [first exposure, window end] is treatment-emergent. A missing onset cannot be ruled pre-treatment, so a treated subject's event with a missing onset is flagged Y; an untreated subject (no first exposure) is never treatment-emergent. */ if not missing(treatment) then do; if missing(onset) then TRTEMFL='Y'; else if onset>=treatment and onset<=window_end then TRTEMFL='Y'; end;run;proc sort data=events(where=(TRTEMFL='Y' and not missing(onset))) out=eligible; by STUDYID USUBJID onset AESEQ; run;data firstevent; set eligible; by STUDYID USUBJID; if first.USUBJID; keep STUDYID USUBJID AESEQ; run;proc sql; create table result as select a.*,case when not missing(b.AESEQ) then 'Y' else '' end as AOCCFL from events as a left join firstevent as b on a.STUDYID=b.STUDYID and a.USUBJID=b.USUBJID and a.AESEQ=b.AESEQ; quit;proc sql; create table final as select STUDYID, USUBJID, AESEQ, AETERM, ASTDTM, TRTSDTM, TEENDDTM, TRTEMFL, AOCCFL from result;quit;proc export data=final outfile="/app/output/adae.csv" dbms=csv replace; run;
yamaa
Comments
Signed in with GitHub; saved in repository Discussions