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) with an analysis start date
(ASTDT) completed from the collected start at whatever precision
it was collected, a flag (ASTDTF) marking the dates whose day was
supplied, and a treatment emergence flag (TRTEMFL).
Input: adverse event records carrying the reported term
(AETERM) and the collected start (AESTDTC): a full date, a year
and month, a year alone, non-date text, or nothing at all, plus the
first-exposure date (TRTSDT) from the subject-level analysis
dataset (ADSL), empty when the subject has no ADSL record.
Variables:
ASTDTis the analysis start date. A fully collected date is used as it stands. A year and month is completed to the 15th. A year alone, non-date text, and a missing value give no analysis date.ASTDTCis the same analysis date written as text, empty when there is no analysis date.ASTDTFisDwhen the day was supplied to complete the date. It is empty when the date was collected in full and when no analysis date could be formed, so the flag always matches the date shown. In CDISC terms only the day was imputed, which is the level of imputation the flag records.TRTEMFLisYwhen the analysis start falls on or afterTRTSDT. It stays empty when there is no analysis date, when the event started before first exposure, or when the subject's first-exposure date is unknown. A supplied day counts exactly as a collected one would, soASTDTFtells a reader which flagged events rested on a supplied day.
Note: a completed date is never placed before first exposure.
When the 15th would fall before TRTSDT, the date moves forward to
the exposure date, which the collected month still allows. When the
whole collected month ends before the exposure date, no day it
allows can satisfy that, so the event is left without an analysis
date rather than moved into a month nobody recorded. A fully
collected date is left exactly as collected even when it falls
before TRTSDT, because there is nothing about it to choose.
Inputs
Under review2 source filesinput/adsl.csv
Edit3 rows| STUDYID | USUBJID | TRTSDT |
|---|---|---|
| CATH | 2025-01-10 | |
| CATH | 2025-03-20 | |
| CATH | 2025-02-15 |
input/ae.csv
Edit13 rows| STUDYID | USUBJID | AESEQ | AETERM | AESTDTC |
|---|---|---|---|---|
| CATH | 1 | HEADACHE | 2025-01-15 | |
| CATH | 2 | NAUSEA | 2025-01 | |
| CATH | 3 | ECZEMA FLARE | 2025 | |
| CATH | 4 | DIZZINESS | UNKNOWN | |
| CATH | 5 | FATIGUE | — | |
| CATH | 6 | RASH | 2025-02-20 | |
| CATH | 1 | PYREXIA | 2025-03 | |
| CATH | 2 | COUGH | 2025-02 | |
| CATH | 3 | INSOMNIA | 2025-04-05 | |
| CATH | 4 | MIGRAINE | 2025-01-05 | |
| CATH | 7 | FLUSHING | 2025-01-10 | |
| CATH | 1 | BACK PAIN | 2025-04 | |
| CATH | 1 | VOMITING | 2025-02 |
Expected output
Under review13 expected rowsexpected/adae.csv
Edit13 rows| STUDYID | USUBJID | AESEQ | AETERM | AESTDTC | ASTDT | ASTDTC | ASTDTF | TRTSDT | TRTEMFL |
|---|---|---|---|---|---|---|---|---|---|
| CATH | 1 | HEADACHE | 2025-01-15 | 2025-01-15 | 2025-01-15 | — | 2025-01-10 | Y | |
| CATH | 2 | NAUSEA | 2025-01 | 2025-01-15 | 2025-01-15 | D | 2025-01-10 | Y | |
| CATH | 3 | ECZEMA FLARE | 2025 | — | — | — | 2025-01-10 | — | |
| CATH | 4 | DIZZINESS | UNKNOWN | — | — | — | 2025-01-10 | — | |
| CATH | 5 | FATIGUE | — | — | — | — | 2025-01-10 | — | |
| CATH | 6 | RASH | 2025-02-20 | 2025-02-20 | 2025-02-20 | — | 2025-01-10 | Y | |
| CATH | 1 | PYREXIA | 2025-03 | 2025-03-20 | 2025-03-20 | D | 2025-03-20 | Y | |
| CATH | 2 | COUGH | 2025-02 | — | — | — | 2025-03-20 | — | |
| CATH | 3 | INSOMNIA | 2025-04-05 | 2025-04-05 | 2025-04-05 | — | 2025-03-20 | Y | |
| CATH | 4 | MIGRAINE | 2025-01-05 | 2025-01-05 | 2025-01-05 | — | 2025-03-20 | — | |
| CATH | 7 | FLUSHING | 2025-01-10 | 2025-01-10 | 2025-01-10 | — | 2025-01-10 | Y | |
| CATH | 1 | BACK PAIN | 2025-04 | 2025-04-15 | 2025-04-15 | D | — | — | |
| CATH | 1 | VOMITING | 2025-02 | 2025-02-15 | 2025-02-15 | D | 2025-02-15 | Y |
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 | AESTDTC | Start Date/Time of Adverse Event | character | Copy value from AE.AESTDTC. | Predecessor | ||
| ADAE | TRTSDT | Date of First Exposure to Treatment | numeric | ISO 8601 | Copy value from ADSL.TRTSDT. | Predecessor | |
| ADAE | ASTDT | Analysis Start Date | numeric | ISO 8601 | Impute incomplete date from AESTDTC, defaulting day=15, never before TRTSDT; a missing source → blank; invalid text → blank. | Derived | |
| ADAE | ASTDTC | Analysis Start Date (C) | character | Copy value from ASTDT. | Derived | ||
| ADAE | ASTDTF | Analysis Start Date Imputation Flag | character | D | If ASTDTPR = 'M' then "D"; otherwise blank. | Derived | |
| ADAE | TRTEMFL | Treatment Emergent Analysis Flag | character | Y | "Y" when ASTDT >= TRTSDT; blank otherwise. | Derived |
| Variable | Permitted values |
|---|---|
| ASTDTF | D |
| TRTEMFL | 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-partial-dates/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, AESTDTC, ASTDT, ASTDTC, ASTDTF, TRTSDT, TRTEMFL
ASTDT is the analysis start date. A fully collected date is used as it stands. A collected year and month is completed to the 15th. A year alone, non-date text, and a missing value give no analysis date. ASTDTC is the same analysis date written as YYYY-MM-DD text, and has no value when there is no analysis date. ASTDTF is D when the day was supplied to complete the date, and has no value otherwise.
A completed date is never placed before first exposure. When the 15th would fall before TRTSDT, the date moves forward to the exposure date. When the whole collected month ends before the exposure date, the event is left without an analysis date. A fully collected date stays exactly as collected even when it falls before TRTSDT.
TRTEMFL is Y when the analysis start falls on or after TRTSDT. It has no value when there is no analysis date, when the event started before first exposure, or when the first-exposure date is unknown. A supplied day counts exactly as a collected one would.
Read the source datasets from /app/input and save the completed dataset as /app/output/adae.csv.
prompts/adam-adae-partial-dates/conventions.md
Edit14 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, AESTDTC, ASTDT, ASTDTC, ASTDTF, TRTSDT, TRTEMFL
ASTDTC is the analysis date written as YYYY-MM-DD text. ASTDTF is D or has no value.
TRTEMFL 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-partial-dates/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, AESTDTC, ASTDT, ASTDTC, ASTDTF, TRTSDT, TRTEMFL
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-partial-dates/result.R
Edit63 lines# Reference solution for the yamaa benchmark adam-adae-partial-dates (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(lubridate, 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(TRTSDT = col_date(), .default = col_character())) |> select(USUBJID, TRTSDT)adae <- ae |> left_join(adsl, by = "USUBJID") |> mutate( is_full = str_detect(AESTDTC, "^\\d{4}-\\d{2}-\\d{2}$"), is_month = str_detect(AESTDTC, "^\\d{4}-\\d{2}$"), # A year and month is completed to the 15th. completed = if_else( is_month, ymd(paste0(AESTDTC, "-15"), quiet = TRUE), ymd(AESTDTC, quiet = TRUE) ), completed = if_else(is_full | is_month, completed, as.Date(NA)), # A completed date is never placed before first exposure. When the # whole collected month ends before the exposure date, no day it # allows can satisfy that, so the event is left without a date. month_end = if_else( is_month, completed + days(days_in_month(completed) - 15L), completed ), month_before_trt = is_month & !is.na(month_end) & !is.na(TRTSDT) & month_end < TRTSDT, ASTDT = case_when( month_before_trt ~ as.Date(NA), is_month & !is.na(completed) & !is.na(TRTSDT) & completed < TRTSDT ~ TRTSDT, .default = completed ), ASTDTC = if_else(is.na(ASTDT), NA_character_, as.character(ASTDT)), ASTDTF = if_else(is_month & !is.na(ASTDT), "D", NA_character_), TRTEMFL = if_else( !is.na(ASTDT) & !is.na(TRTSDT) & ASTDT >= TRTSDT, "Y", NA_character_ ) ) |> select( STUDYID, USUBJID, AESEQ, AETERM, AESTDTC, ASTDT, ASTDTC, ASTDTF, TRTSDT, TRTEMFL )dir.create("/app/output", showWarnings = FALSE)write_csv(adae, "/app/output/adae.csv", na = "")solutions/adam-adae-partial-dates/result.py
Edit94 lines# Reference solution for the yamaa benchmark adam-adae-partial-dates (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.import calendarfrom 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).select("USUBJID", "TRTSDT")def complete_row(collected: str | None, trt: str | None) -> tuple[str | None, str | None]: """The analysis date and its imputation flag for one collected start.""" if collected is None: return None, None full = len(collected) == 10 and collected[4] == "-" and collected[7] == "-" month = len(collected) == 7 and collected[4] == "-" try: if full: year, mon, day = int(collected[0:4]), int(collected[5:7]), int(collected[8:10]) last_day = calendar.monthrange(year, mon)[1] if day < 1 or day > last_day: return None, None completed = f"{year:04d}-{mon:02d}-{day:02d}" # A fully collected date stays exactly as collected. return completed, None if not month: return None, None year, mon = int(collected[0:4]), int(collected[5:7]) completed = f"{year:04d}-{mon:02d}-15" if trt is None: return completed, "D" # A completed date is never placed before first exposure. When # the whole collected month ends before the exposure date, the # event is left without an analysis date. last_day = calendar.monthrange(year, mon)[1] month_end = f"{year:04d}-{mon:02d}-{last_day:02d}" if month_end < trt: return None, None if completed < trt: return trt, "D" return completed, "D" except ValueError: return None, Nonejoined = ae.join(adsl, on="USUBJID", how="left", maintain_order="left")records = []for row in joined.to_dicts(): ast, flag = complete_row(row["AESTDTC"], row["TRTSDT"]) trtemfl = ( "Y" if ast is not None and row["TRTSDT"] is not None and ast >= row["TRTSDT"] else None ) records.append( { "STUDYID": row["STUDYID"], "USUBJID": row["USUBJID"], "AESEQ": row["AESEQ"], "AETERM": row["AETERM"], "AESTDTC": row["AESTDTC"], "ASTDT": ast, "ASTDTC": ast, "ASTDTF": flag, "TRTSDT": row["TRTSDT"], "TRTEMFL": trtemfl, } )adae = pl.DataFrame( records, schema={ "STUDYID": pl.String, "USUBJID": pl.String, "AESEQ": pl.Int64, "AETERM": pl.String, "AESTDTC": pl.String, "ASTDT": pl.String, "ASTDTC": pl.String, "ASTDTF": pl.String, "TRTSDT": pl.String, "TRTEMFL": pl.String, },)Path("/app/output").mkdir(exist_ok=True)adae.write_csv("/app/output/adae.csv")solutions/adam-adae-partial-dates/result.sas
Edit39 lines/* opensas reference solution for the yamaa benchmark adam-adae-partial-dates. 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 TRTSDT $1024; infile "/app/input/adsl.csv" dsd dlm="," firstobs=2 truncover lrecl=32767; input STUDYID : $char1024. USUBJID : $char1024. TRTSDT : $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.TRTSDT from ae as a left join adsl as b on a.STUDYID=b.STUDYID and a.USUBJID=b.USUBJID; quit;data result; length ASTDT ASTDTC $10 ASTDTF TRTEMFL $1; set joined; treatment=input(TRTSDT,yymmdd10.); analysis=.; if prxmatch('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/',strip(AESTDTC)) then analysis=input(AESTDTC,yymmdd10.); else if prxmatch('/^[0-9]{4}-[0-9]{2}$/',strip(AESTDTC)) then do; analysis=input(cats(AESTDTC,'-15'),yymmdd10.); if not missing(analysis) then do; if not missing(treatment) and intnx('month',analysis,0,'end')<treatment then analysis=.; else do; analysis=max(analysis,treatment); ASTDTF='D'; end; end; end; if not missing(analysis) then do; ASTDT=put(analysis,yymmdd10.); ASTDTC=ASTDT; if not missing(treatment) and analysis>=treatment then TRTEMFL='Y'; end;run;proc sql; create table final as select STUDYID, USUBJID, AESEQ, AETERM, AESTDTC, ASTDT, ASTDTC, ASTDTF, TRTSDT, TRTEMFL 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