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: mark each subject's end-of-treatment record for every laboratory
test (EOTFL), carrying the protocol endpoint qualifier it rests on
(ENDPOINT).
Input: laboratory (LB) records carry a numeric sequence number, a test
code (LBTESTCD), a visit number (VISITNUM), and a numeric result.
Supplemental laboratory
qualifier (SUPPLB) records carry the same sequence as eight-character,
space-padded text, one qualifier name and value per record; only the
protocol endpoint qualifier is read.
Variables:
AVALis the numeric laboratory result.ENDPOINTisYwhen a supplemental endpoint qualifier with the same study, subject, and sequence number marks the record; empty otherwise.EOTFLisYon one record per subject and test: the endpoint-marked record when there is one, otherwise the record from the latest visit. Every other record is empty.
Note: the endpoint qualifier decides the choice even when a later visit exists, so the flag can sit before the subject's last visit. A record wins the flag even when its result is missing, and a group with a single record still gets the flag. Other qualifiers on the same record, and endpoint qualifiers for records the laboratory data does not hold, change nothing.
Inputs
Under review2 source filesinput/lb.csv
Edit12 rows| STUDYID | USUBJID | LBSEQ | LBTESTCD | VISITNUM | LBSTRESN |
|---|---|---|---|---|---|
| YAMAA-01 | 1 | ALB | 1 | 4 | |
| YAMAA-01 | 2 | ALB | 2 | 4.2 | |
| YAMAA-01 | 3 | ALB | 3 | 4.1 | |
| YAMAA-01 | 4 | CREAT | 1 | 80 | |
| YAMAA-01 | 5 | CREAT | 2 | 82 | |
| YAMAA-01 | 6 | CREAT | 3 | 85 | |
| YAMAA-01 | 1 | ALB | 1 | 3.9 | |
| YAMAA-01 | 2 | ALB | 2 | 4 | |
| YAMAA-01 | 1 | ALB | 1 | 4.3 | |
| YAMAA-01 | 1 | ALB | 1 | — | |
| YAMAA-01 | 2 | ALB | 2 | 4.4 | |
| YAMAA-01 | 1 | CREAT | 3 | 95 |
input/supplb.csv
Edit6 rows| STUDYID | RDOMAIN | USUBJID | IDVAR | IDVARVAL | QNAM | QLABEL | QVAL |
|---|---|---|---|---|---|---|---|
| YAMAA-01 | LB | LBSEQ | 2 | ENDPOINT | Protocol Endpoint Record | Y | |
| YAMAA-01 | LB | LBSEQ | 2 | LBTMSHI | Result to Upper Limit Ratio | 0.9 | |
| YAMAA-01 | LB | LBSEQ | 1 | LBTMSHI | Result to Upper Limit Ratio | 0.8 | |
| YAMAA-01 | LB | LBSEQ | 7 | ENDPOINT | Protocol Endpoint Record | Y | |
| YAMAA-01 | LB | LBSEQ | 1 | ENDPOINT | Protocol Endpoint Record | Y | |
| YAMAA-01 | LB | LBSEQ | 1 | ENDPOINT | Protocol Endpoint Record | Y |
Expected output
Under review12 expected rowsexpected/adlb.csv
Edit12 rows| STUDYID | USUBJID | LBSEQ | LBTESTCD | VISITNUM | AVAL | ENDPOINT | EOTFL |
|---|---|---|---|---|---|---|---|
| YAMAA-01 | 1 | ALB | 1 | 4 | — | — | |
| YAMAA-01 | 2 | ALB | 2 | 4.2 | Y | Y | |
| YAMAA-01 | 3 | ALB | 3 | 4.1 | — | — | |
| YAMAA-01 | 4 | CREAT | 1 | 80 | — | — | |
| YAMAA-01 | 5 | CREAT | 2 | 82 | — | — | |
| YAMAA-01 | 6 | CREAT | 3 | 85 | — | Y | |
| YAMAA-01 | 1 | ALB | 1 | 3.9 | — | — | |
| YAMAA-01 | 2 | ALB | 2 | 4 | — | Y | |
| YAMAA-01 | 1 | ALB | 1 | 4.3 | — | Y | |
| YAMAA-01 | 1 | ALB | 1 | — | Y | Y | |
| YAMAA-01 | 2 | ALB | 2 | 4.4 | — | — | |
| YAMAA-01 | 1 | CREAT | 3 | 95 | Y | Y |
Comments and assessment materials
| Dataset Name | Variable Name | Variable Label | Type | Codelist/Controlled Terms | Core | Computational Method | Origin |
|---|---|---|---|---|---|---|---|
| ADLB | STUDYID | Study Identifier | character | Copy value from LB.STUDYID. | Predecessor | ||
| ADLB | USUBJID | Unique Subject Identifier | character | Copy value from LB.USUBJID. | Predecessor | ||
| ADLB | LBSEQ | Sequence Number | numeric | Copy value from LB.LBSEQ. | Predecessor | ||
| ADLB | LBTESTCD | Lab Test or Examination Short Name | character | Copy value from LB.LBTESTCD. | Predecessor | ||
| ADLB | VISITNUM | Visit Number | numeric | Copy value from LB.VISITNUM. | Predecessor | ||
| ADLB | AVAL | Analysis Value | numeric | Copy value from LB.LBSTRESN. | Predecessor | ||
| ADLB | ENDPOINT | Protocol Endpoint Record | character | Take ENDPOINT from the LB record matching on STUDYID, USUBJID and LBSEQ, where ENDPOINT is derived as QVAL from the SUPPLB record whose STUDYID equals LB.STUDYID, USUBJID equals LB.USUBJID and IDVARVAL equals LB.LBSEQ padded on the left with spaces to at least 8 characters, where SUPPLB.QNAM = 'ENDPOINT', blank when unmatched, and a row with no match is an error. | Derived | ||
| ADLB | EOTFL | End of Treatment Record Flag | character | "Y" when EOT_SEQ = 1, with EOT_SEQ taken from the LB record matching on STUDYID, USUBJID and LBSEQ, where EOT_SEQ is derived as row number within each group of LB.USUBJID, LB.LBTESTCD, ordered by ENDPOINT descending then LB.VISITNUM descending, and a row with no match is an error; blank otherwise. | Derived |
| 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-adlb-end-of-treatment/full.md
Edit22 linesFollowing CDISC ADaM standards, use the provided LB and SUPPLB datasets to create an ADLB dataset with one record per laboratory record.
The output dataset should contain the following columns in this order: STUDYID, USUBJID, LBSEQ, LBTESTCD, VISITNUM, AVAL, ENDPOINT, EOTFL
AVAL is the numeric laboratory result.
ENDPOINT is Y when a supplemental endpoint qualifier with the same study, subject, and sequence number marks the record; it has no value otherwise. Only the protocol endpoint qualifier is read; other qualifiers change nothing.
EOTFL is Y on one record per subject and test: the endpoint-marked record when there is one, otherwise the record from the latest visit. Every other record has no value. The endpoint qualifier decides even when a later visit exists, and a record wins the flag even when its result is missing.
Read the source datasets from /app/input and save the completed dataset as /app/output/adlb.csv.
prompts/adam-adlb-end-of-treatment/conventions.md
Edit13 linesFollowing CDISC ADaM standards, use the provided LB and SUPPLB datasets to create an ADLB dataset with one record per laboratory record.
The output dataset should contain the following columns in this order: STUDYID, USUBJID, LBSEQ, LBTESTCD, VISITNUM, AVAL, ENDPOINT, EOTFL
ENDPOINT is Y or has no value.
EOTFL is Y or has no value.
Read the source datasets from /app/input and save the completed dataset as /app/output/adlb.csv.
prompts/adam-adlb-end-of-treatment/brief.md
Edit9 linesFollowing CDISC ADaM standards, use the provided LB and SUPPLB datasets to create an ADLB dataset with one record per laboratory record.
The output dataset should contain the following columns in this order: STUDYID, USUBJID, LBSEQ, LBTESTCD, VISITNUM, AVAL, ENDPOINT, EOTFL
Read the source datasets from /app/input and save the completed dataset as /app/output/adlb.csv.
run.R
Edit4 lineslibrary(yamaa)adlb <- yamaa_domain("spec.yaml")$outputadlbrun.py
Edit4 linesimport yamaaadlb = yamaa.yamaa_domain("spec.yaml").outputadlbsolutions/adam-adlb-end-of-treatment/result.R
Edit67 lines# Reference solution for the yamaa benchmark adam-adlb-end-of-treatment (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)lb <- read_csv( "/app/input/lb.csv", col_types = cols( LBSEQ = col_integer(), VISITNUM = col_integer(), LBSTRESN = col_double(), .default = col_character() ))supp <- read_csv( "/app/input/supplb.csv", col_types = cols(.default = col_character()))# ENDPOINT is Y when a supplemental endpoint qualifier with the same# study, subject, and sequence number marks the record. Only the protocol# endpoint qualifier is read.endpoint_keys <- supp |> filter(QNAM %in% "ENDPOINT") |> transmute( STUDYID, USUBJID, SEQ_TRIM = str_trim(IDVARVAL), ENDPOINT = "Y" )marked <- lb |> mutate(SEQ_TRIM = as.character(LBSEQ), AVAL = LBSTRESN) |> left_join(endpoint_keys, by = c("STUDYID", "USUBJID", "SEQ_TRIM")) |> select(-SEQ_TRIM)# EOTFL is Y on one record per subject and test: the endpoint-marked# record when there is one, otherwise the record from the latest visit.endpoint_winners <- marked |> filter(ENDPOINT %in% "Y") |> group_by(STUDYID, USUBJID, LBTESTCD) |> summarise(WIN_ENDPOINT = min(LBSEQ), .groups = "drop")latest_winners <- marked |> arrange(desc(VISITNUM), desc(LBSEQ)) |> distinct(STUDYID, USUBJID, LBTESTCD, .keep_all = TRUE) |> transmute(STUDYID, USUBJID, LBTESTCD, WIN_LATEST = LBSEQ)winners <- latest_winners |> left_join(endpoint_winners, by = c("STUDYID", "USUBJID", "LBTESTCD")) |> mutate(WIN_LBSEQ = coalesce(WIN_ENDPOINT, WIN_LATEST), EOTFL = "Y") |> select(STUDYID, USUBJID, LBTESTCD, WIN_LBSEQ, EOTFL)adlb <- marked |> left_join( winners, by = c("STUDYID", "USUBJID", "LBTESTCD", "LBSEQ" = "WIN_LBSEQ") ) |> arrange(USUBJID, LBTESTCD, LBSEQ) |> select(STUDYID, USUBJID, LBSEQ, LBTESTCD, VISITNUM, AVAL, ENDPOINT, EOTFL)dir.create("/app/output", showWarnings = FALSE)write_csv(adlb, "/app/output/adlb.csv", na = "")solutions/adam-adlb-end-of-treatment/result.py
Edit82 lines# Reference solution for the yamaa benchmark adam-adlb-end-of-treatment (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 pllb = pl.read_csv("/app/input/lb.csv", infer_schema=False).with_columns( pl.col("LBSEQ").cast(pl.Int64), pl.col("VISITNUM").cast(pl.Int64, strict=False), pl.col("LBSTRESN").cast(pl.Float64, strict=False).alias("AVAL"),)supp = pl.read_csv("/app/input/supplb.csv", infer_schema=False)# ENDPOINT is Y when a supplemental endpoint qualifier with the same# study, subject, and sequence number marks the record. Only the protocol# endpoint qualifier is read. IDVARVAL is space-padded, so compare on the# trimmed sequence number.endpoint_keys = ( supp.filter(pl.col("QNAM") == "ENDPOINT") .with_columns(pl.col("IDVARVAL").str.strip_chars().alias("SEQ_TRIM")) .select("STUDYID", "USUBJID", "SEQ_TRIM") .with_columns(pl.lit("Y").alias("ENDPOINT")))marked = ( lb.with_columns(SEQ_TRIM=pl.col("LBSEQ").cast(pl.String)) .join( endpoint_keys, on=["STUDYID", "USUBJID", "SEQ_TRIM"], how="left", maintain_order="left", ) .drop("SEQ_TRIM"))# EOTFL is Y on one record per subject and test: the endpoint-marked# record when there is one, otherwise the record from the latest visit.endpoint_winners = ( marked.filter(pl.col("ENDPOINT") == "Y") .group_by("STUDYID", "USUBJID", "LBTESTCD") .agg(pl.col("LBSEQ").min().alias("WIN_ENDPOINT")))latest_winners = ( marked.sort(["VISITNUM", "LBSEQ"], descending=[True, True], nulls_last=True) .unique(["STUDYID", "USUBJID", "LBTESTCD"], keep="first", maintain_order=True) .select("STUDYID", "USUBJID", "LBTESTCD", WIN_LATEST="LBSEQ"))winners = ( latest_winners.join( endpoint_winners, on=["STUDYID", "USUBJID", "LBTESTCD"], how="left" ) .with_columns(WIN_LBSEQ=pl.coalesce("WIN_ENDPOINT", "WIN_LATEST")) .select("STUDYID", "USUBJID", "LBTESTCD", "WIN_LBSEQ") .with_columns(pl.lit("Y").alias("EOTFL")))adlb = ( marked.join( winners, left_on=["STUDYID", "USUBJID", "LBTESTCD", "LBSEQ"], right_on=["STUDYID", "USUBJID", "LBTESTCD", "WIN_LBSEQ"], how="left", ) .select( "STUDYID", "USUBJID", "LBSEQ", "LBTESTCD", "VISITNUM", "AVAL", "ENDPOINT", "EOTFL", ) .sort(["USUBJID", "LBTESTCD", "LBSEQ"]))Path("/app/output").mkdir(exist_ok=True)adlb.write_csv("/app/output/adlb.csv")solutions/adam-adlb-end-of-treatment/result.sas
Edit29 lines/* opensas reference solution for the yamaa benchmark adam-adlb-end-of-treatment. Reads the benchmark inputs and derives the requested output. Execute with the existing opensas runtime: opensas /app/output/result.sas. */data lb; length STUDYID USUBJID LBTESTCD $1024; infile "/app/input/lb.csv" dsd dlm="," firstobs=2 truncover lrecl=32767; input STUDYID : $char1024. USUBJID : $char1024. LBSEQ LBTESTCD : $char1024. VISITNUM LBSTRESN;run;data supplb; length STUDYID RDOMAIN USUBJID IDVAR IDVARVAL QNAM QLABEL QVAL $1024; infile "/app/input/supplb.csv" dsd dlm="," firstobs=2 truncover lrecl=32767; input STUDYID : $char1024. RDOMAIN : $char1024. USUBJID : $char1024. IDVAR : $char1024. IDVARVAL : $char1024. QNAM : $char1024. QLABEL : $char1024. QVAL : $char1024.;run;data supplb_key; set supplb; PARENTSEQ=input(IDVARVAL,?? best32.); run;proc sql; create table joined as select a.*,a.LBSTRESN as AVAL,b.QVAL as ENDPOINT from lb as a left join supplb_key as b on a.STUDYID=b.STUDYID and a.USUBJID=b.USUBJID and b.RDOMAIN='LB' and b.IDVAR='LBSEQ' and a.LBSEQ=b.PARENTSEQ and b.QNAM='ENDPOINT';quit;data ordered; set joined; priority=0; if ENDPOINT='Y' then priority=1; run;proc sort data=ordered; by STUDYID USUBJID LBTESTCD descending priority descending VISITNUM LBSEQ; run;data result; length EOTFL $1; set ordered; by STUDYID USUBJID LBTESTCD; if first.LBTESTCD then EOTFL='Y'; run;proc sql; create table final as select STUDYID, USUBJID, LBSEQ, LBTESTCD, VISITNUM, AVAL, ENDPOINT, EOTFL from result;quit;proc export data=final outfile="/app/output/adlb.csv" dbms=csv replace; run;
yamaa
Comments
Signed in with GitHub; saved in repository Discussions