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: for each adverse event, name the subject's most recent
earlier serious event (PRIOR_SAEFL, PRIOR_SAEDECOD,
PRIOR_SAESEQ), the subject's first serious event
(FIRST_SAEDECOD, FIRST_SAESEQ), and the subject's immediately
preceding event (PREV_AEDECOD).
Input: adverse event records with study, subject, and sequence
(STUDYID, USUBJID, AESEQ), the dictionary term (AEDECOD),
and whether the event was serious (AESER).
Variables:
PRIOR_SAEFL:Yon a non-serious event when the subject had a serious event with a smaller sequence number, empty otherwise.PRIOR_SAEDECOD/PRIOR_SAESEQ: the term and sequence number of that most recent earlier serious event, empty when there is none.FIRST_SAEDECOD/FIRST_SAESEQ: the term and sequence number of the subject's first serious event, empty when the subject had no serious event.PREV_AEDECOD: the term of the subject's event with the next smaller sequence number, serious or not; empty on the subject's first event, and empty when the preceding event has no coded term.
Note: a serious event with no coded term still counts: the prior
flag is Y and its sequence number is named, while the term fields
stay empty. The serious events are laid down first, so a serious
event's own prior and first serious event fields stay empty, because
they cannot look back at records that are still being written. The
preceding event is named only after every event is in place, so it
can name an event of either kind.
Inputs
Under review1 source fileinput/ae.csv
Edit14 rows| STUDYID | USUBJID | AESEQ | AEDECOD | AESER |
|---|---|---|---|---|
| YAMAA-01 | 1 | HEADACHE | Y | |
| YAMAA-01 | 2 | COUGH | N | |
| YAMAA-01 | 3 | NAUSEA | Y | |
| YAMAA-01 | 4 | FATIGUE | N | |
| YAMAA-01 | 5 | RASH | N | |
| YAMAA-01 | 6 | — | Y | |
| YAMAA-01 | 7 | MYALGIA | N | |
| YAMAA-01 | 1 | DIZZINESS | N | |
| YAMAA-01 | 2 | FEVER | Y | |
| YAMAA-01 | 3 | VOMITING | N | |
| YAMAA-01 | 1 | BACK PAIN | N | |
| YAMAA-01 | 2 | INFLUENZA | N | |
| YAMAA-01 | 1 | CHEST PAIN | Y | |
| YAMAA-01 | 1 | HYPERTENSION | N |
Expected output
Under review14 expected rowsexpected/adae.csv
Edit14 rows| STUDYID | USUBJID | AESEQ | AEDECOD | AESER | PRIOR_SAEFL | PRIOR_SAEDECOD | PRIOR_SAESEQ | FIRST_SAEDECOD | FIRST_SAESEQ | PREV_AEDECOD |
|---|---|---|---|---|---|---|---|---|---|---|
| YAMAA-01 | 1 | HEADACHE | Y | — | — | — | — | — | — | |
| YAMAA-01 | 3 | NAUSEA | Y | — | — | — | — | — | COUGH | |
| YAMAA-01 | 6 | — | Y | — | — | — | — | — | RASH | |
| YAMAA-01 | 2 | FEVER | Y | — | — | — | — | — | DIZZINESS | |
| YAMAA-01 | 1 | CHEST PAIN | Y | — | — | — | — | — | — | |
| YAMAA-01 | 2 | COUGH | N | Y | HEADACHE | 1 | HEADACHE | 1 | HEADACHE | |
| YAMAA-01 | 4 | FATIGUE | N | Y | NAUSEA | 3 | HEADACHE | 1 | NAUSEA | |
| YAMAA-01 | 5 | RASH | N | Y | NAUSEA | 3 | HEADACHE | 1 | FATIGUE | |
| YAMAA-01 | 7 | MYALGIA | N | Y | — | 6 | HEADACHE | 1 | — | |
| YAMAA-01 | 1 | DIZZINESS | N | — | — | — | FEVER | 2 | — | |
| YAMAA-01 | 3 | VOMITING | N | Y | FEVER | 2 | FEVER | 2 | FEVER | |
| YAMAA-01 | 1 | BACK PAIN | N | — | — | — | — | — | — | |
| YAMAA-01 | 2 | INFLUENZA | N | — | — | — | — | — | BACK PAIN | |
| YAMAA-01 | 1 | HYPERTENSION | N | — | — | — | — | — | — |
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 | AEDECOD | Dictionary-Derived Term | character | Copy value from AE.AEDECOD. | Predecessor | ||
| ADAE | AESER | Serious Event | character | Copy value from AE.AESER. | Predecessor | ||
| ADAE | PRIOR_SAEFL | Prior Serious Event Flag | character | Set per constructed row; see the Row construction sheet. | Derived | ||
| ADAE | PRIOR_SAEDECOD | Prior Serious Event Dictionary-Derived Term | character | Set per constructed row; see the Row construction sheet. | Derived | ||
| ADAE | PRIOR_SAESEQ | Prior Serious Event Sequence Number | numeric | Set per constructed row; see the Row construction sheet. | Derived | ||
| ADAE | FIRST_SAEDECOD | First Serious Event Dictionary-Derived Term | character | Set per constructed row; see the Row construction sheet. | Derived | ||
| ADAE | FIRST_SAESEQ | First Serious Event Sequence Number | numeric | Set per constructed row; see the Row construction sheet. | Derived | ||
| ADAE | PREV_AEDECOD | Preceding Event Dictionary-Derived Term | character | Take AEDECOD from the first already-derived row of this dataset matching on STUDYID and USUBJID, where AESEQ < AE.AESEQ, ordered by AESEQ descending, and no match yields blank. | Derived |
| Template | Include when | PRIOR_SAEFL | PRIOR_SAEDECOD | PRIOR_SAESEQ | FIRST_SAEDECOD | FIRST_SAESEQ |
|---|---|---|---|---|---|---|
| serious | AE.AESER = 'Y' | Constant "None" | Constant "None" | Constant "None" | Constant "None" | Constant "None" |
| nonserious | AE.AESER = 'N' | If AESEQ IS NOT NULL, with AESEQ taken from the first already-derived row of this dataset matching on STUDYID and USUBJID, where SELF.AESER = 'Y' AND SELF.AESEQ < AE.AESEQ, ordered by SELF.AESEQ descending, and no match yields blank then "Y"; otherwise "None" | Copy AEDECOD from the first already-derived row of this dataset matching on STUDYID and USUBJID, where SELF.AESER = 'Y' AND SELF.AESEQ < AE.AESEQ, ordered by SELF.AESEQ descending, and no match yields blank | Copy AESEQ from the first already-derived row of this dataset matching on STUDYID and USUBJID, where SELF.AESER = 'Y' AND SELF.AESEQ < AE.AESEQ, ordered by SELF.AESEQ descending, and no match yields blank | Copy AEDECOD from the first already-derived row of this dataset matching on STUDYID and USUBJID, where SELF.AESER = 'Y', ordered by SELF.AESEQ, and no match yields blank | Copy AESEQ from the first already-derived row of this dataset matching on STUDYID and USUBJID, where SELF.AESER = 'Y', ordered by SELF.AESEQ, and no match yields blank |
| 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-prior-serious-event/full.md
Edit24 linesFollowing CDISC ADaM standards, use the provided AE dataset 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, AEDECOD, AESER, PRIOR_SAEFL, PRIOR_SAEDECOD, PRIOR_SAESEQ, FIRST_SAEDECOD, FIRST_SAESEQ, PREV_AEDECOD
PRIOR_SAEFL is Y on a non-serious event when the subject had a serious event with a smaller sequence number, and has no value otherwise. PRIOR_SAEDECOD and PRIOR_SAESEQ name the term and sequence number of that most recent earlier serious event, and have no value when there is none. FIRST_SAEDECOD and FIRST_SAESEQ name the term and sequence number of the subject's first serious event, and have no value when the subject had no serious event. A serious event leaves its own prior and first serious event fields empty. A serious event with no coded term still counts: the prior flag is Y and its sequence number is named, while the term fields stay empty.
PREV_AEDECOD names the term of the subject's event with the next smaller sequence number, serious or not. It has no value on the subject's first event, and when the preceding event has no coded term.
Read the source datasets from /app/input and save the completed dataset as /app/output/adae.csv.
prompts/adam-adae-prior-serious-event/conventions.md
Edit11 linesFollowing CDISC ADaM standards, use the provided AE dataset 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, AEDECOD, AESER, PRIOR_SAEFL, PRIOR_SAEDECOD, PRIOR_SAESEQ, FIRST_SAEDECOD, FIRST_SAESEQ, PREV_AEDECOD
PRIOR_SAEFL 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-prior-serious-event/brief.md
Edit9 linesFollowing CDISC ADaM standards, use the provided AE dataset 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, AEDECOD, AESER, PRIOR_SAEFL, PRIOR_SAEDECOD, PRIOR_SAESEQ, FIRST_SAEDECOD, FIRST_SAESEQ, PREV_AEDECOD
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-prior-serious-event/result.R
Edit91 lines# Reference solution for the yamaa benchmark adam-adae-prior-serious-event (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)ae <- read_csv( "/app/input/ae.csv", col_types = cols(AESEQ = col_integer(), .default = col_character()))serious <- ae |> filter(AESER %in% "Y") |> arrange(USUBJID, AESEQ)# The subject's first serious event, whatever its term holds.first_sae <- serious |> distinct(USUBJID, .keep_all = TRUE) |> select(USUBJID, FIRST_SAEDECOD = AEDECOD, FIRST_SAESEQ = AESEQ)adae <- ae |> left_join(first_sae, by = "USUBJID") |> group_by(USUBJID) |> arrange(AESEQ, .by_group = TRUE) |> mutate( # The most recent earlier serious event, by sequence number. PRIOR_SAESEQ = sapply( AESEQ, function(s) { earlier <- AESEQ[AESER %in% "Y" & AESEQ < s] if (length(earlier) == 0L) NA_integer_ else max(earlier) } ), PRIOR_SAEDECOD = sapply( PRIOR_SAESEQ, function(s) { if (is.na(s)) NA_character_ else AEDECOD[match(s, AESEQ)] } ), PREV_SEQ = sapply( AESEQ, function(s) { earlier <- AESEQ[AESEQ < s] if (length(earlier) == 0L) NA_integer_ else max(earlier) } ), PREV_AEDECOD = sapply( PREV_SEQ, function(s) { if (is.na(s)) NA_character_ else AEDECOD[match(s, AESEQ)] } ), PREV_AEDECOD = if_else( PREV_AEDECOD == "" | is.na(PREV_AEDECOD), NA_character_, PREV_AEDECOD ), PRIOR_SAEDECOD = if_else( PRIOR_SAEDECOD == "" | is.na(PRIOR_SAEDECOD), NA_character_, PRIOR_SAEDECOD ), FIRST_SAEDECOD = if_else( FIRST_SAEDECOD == "" | is.na(FIRST_SAEDECOD), NA_character_, FIRST_SAEDECOD ) ) |> ungroup() |> mutate( # A serious event leaves its own prior and first fields empty. PRIOR_SAEFL = if_else( AESER %in% "N" & !is.na(PRIOR_SAESEQ), "Y", NA_character_ ), PRIOR_SAEDECOD = if_else(AESER %in% "N", PRIOR_SAEDECOD, NA_character_), PRIOR_SAESEQ = if_else(AESER %in% "N", PRIOR_SAESEQ, NA_integer_), FIRST_SAEDECOD = if_else(AESER %in% "N", FIRST_SAEDECOD, NA_character_), FIRST_SAESEQ = if_else(AESER %in% "N", FIRST_SAESEQ, NA_integer_) ) |> select( STUDYID, USUBJID, AESEQ, AEDECOD, AESER, PRIOR_SAEFL, PRIOR_SAEDECOD, PRIOR_SAESEQ, FIRST_SAEDECOD, FIRST_SAESEQ, PREV_AEDECOD )dir.create("/app/output", showWarnings = FALSE)write_csv(adae, "/app/output/adae.csv", na = "")solutions/adam-adae-prior-serious-event/result.py
Edit72 lines# Reference solution for the yamaa benchmark adam-adae-prior-serious-event (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))records = []for subject, group in ae.sort(["USUBJID", "AESEQ"]).group_by("USUBJID", maintain_order=True): rows = group.sort("AESEQ").to_dicts() serious_seqs = [r["AESEQ"] for r in rows if r["AESER"] == "Y"] first_seq = min(serious_seqs) if serious_seqs else None first_term = next( (r["AEDECOD"] for r in rows if r["AESEQ"] == first_seq), None ) by_seq = {r["AESEQ"]: r for r in rows} for row in rows: seq = row["AESEQ"] earlier_serious = [s for s in serious_seqs if s < seq] prior_seq = max(earlier_serious) if earlier_serious else None prior_term = by_seq.get(prior_seq, {}).get("AEDECOD") if prior_seq else None earlier_all = [r["AESEQ"] for r in rows if r["AESEQ"] < seq] prev_seq = max(earlier_all) if earlier_all else None prev_term = by_seq.get(prev_seq, {}).get("AEDECOD") if prev_seq else None is_nonserious = row["AESER"] == "N" # Only an explicit N receives prior and first serious-event fields. A # serious event with no coded term still counts for the flag and # the sequence number, while the term fields stay empty. records.append( { "STUDYID": row["STUDYID"], "USUBJID": row["USUBJID"], "AESEQ": seq, "AEDECOD": row["AEDECOD"], "AESER": row["AESER"], "PRIOR_SAEFL": None if not is_nonserious or prior_seq is None else "Y", "PRIOR_SAEDECOD": None if not is_nonserious else prior_term, "PRIOR_SAESEQ": None if not is_nonserious else prior_seq, "FIRST_SAEDECOD": None if not is_nonserious else first_term, "FIRST_SAESEQ": None if not is_nonserious else first_seq, "PREV_AEDECOD": prev_term, } )adae = pl.DataFrame( records, schema={ "STUDYID": pl.String, "USUBJID": pl.String, "AESEQ": pl.Int64, "AEDECOD": pl.String, "AESER": pl.String, "PRIOR_SAEFL": pl.String, "PRIOR_SAEDECOD": pl.String, "PRIOR_SAESEQ": pl.Int64, "FIRST_SAEDECOD": pl.String, "FIRST_SAESEQ": pl.Int64, "PREV_AEDECOD": pl.String, },)Path("/app/output").mkdir(exist_ok=True)adae.write_csv("/app/output/adae.csv")solutions/adam-adae-prior-serious-event/result.sas
Edit33 lines/* opensas reference solution for the yamaa benchmark adam-adae-prior-serious-event. Reads the benchmark inputs and derives the requested output. Execute with the existing opensas runtime: opensas /app/output/result.sas. */data ae; length STUDYID USUBJID AEDECOD AESER $1024; infile "/app/input/ae.csv" dsd dlm="," firstobs=2 truncover lrecl=32767; input STUDYID : $char1024. USUBJID : $char1024. AESEQ AEDECOD : $char1024. AESER : $char1024.;run;proc sort data=ae(where=(AESER='Y')) out=serious; by STUDYID USUBJID AESEQ; run;data firsts; set serious; by STUDYID USUBJID; if first.USUBJID; run;proc sql; create table joined as select a.*,b.AEDECOD as firstterm,b.AESEQ as firstseq from ae as a left join firsts as b on a.STUDYID=b.STUDYID and a.USUBJID=b.USUBJID; quit;proc sort data=joined; by STUDYID USUBJID AESEQ; run;data result; length PRIOR_SAEFL $1 PRIOR_SAEDECOD FIRST_SAEDECOD PREV_AEDECOD lastterm prevterm $1024; retain lastterm lastseq prevterm; set joined; by STUDYID USUBJID; if first.USUBJID then do; lastterm=''; lastseq=.; prevterm=''; end; PREV_AEDECOD=prevterm; if AESER='N' then do; PRIOR_SAEDECOD=lastterm; PRIOR_SAESEQ=lastseq; FIRST_SAEDECOD=firstterm; FIRST_SAESEQ=firstseq; if not missing(lastseq) then PRIOR_SAEFL='Y'; end; if AESER='Y' then do; lastterm=AEDECOD; lastseq=AESEQ; end; prevterm=AEDECOD;run;proc sql; create table final as select STUDYID, USUBJID, AESEQ, AEDECOD, AESER, PRIOR_SAEFL, PRIOR_SAEDECOD, PRIOR_SAESEQ, FIRST_SAEDECOD, FIRST_SAESEQ, PREV_AEDECOD 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