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 SDTM: 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: draftEditUnder review
What this benchmark means
README.md

Goal: flag the last laboratory record collected on or before first exposure for each subject, test, and specimen: LBLOBXFL.

Input: long-form Operational Data Model (ODM) data with one row per collected item: a laboratory result, its collection date, or its completion status. A small test dictionary (lb_mapping.csv) translates result items into test codes and specimens. One demographics row per subject carries the reference start date (first exposure).

Variables:

  • LBTESTCD is the test code from the item dictionary; together with the specimen it defines the series the flag is assigned within.
  • LBSPEC is the specimen from the item dictionary; a test measured in more than one specimen is flagged separately per specimen.
  • LBORRES is the result as collected; missing on records that were not done.
  • LBDTC is the collection date as collected.
  • LBSTAT is the completion status as collected; NOT DONE on records without a result.
  • LBLOBXFL is Y on the latest record with a result whose collection date falls on or before the subject's reference start date; blank on every other record.

Note: records without a result never carry the flag, even when they carry the latest date. A subject with no reference start date has the flag on the latest record with a result, since no record falls after exposure. Dates compare at day precision, so a record collected on the day of first exposure still qualifies; of two results collected on the same date, the one with the higher sequence number (LBSEQ) is flagged.

Inputs

Under review
3 source files

input/dm.csv

Edit
2 rows
input/dm.csv
STUDYIDUSUBJIDRFSTDTC
YAMAA-012026-01-15
YAMAA-01—

input/lb_mapping.csv

Edit
4 rows
input/lb_mapping.csv
ItemOIDLBTESTCDLBSPEC
IT.LB.ALT_SERUMALTSERUM
IT.LB.GLUC_SERUMGLUCSERUM
IT.LB.K_SERUMKSERUM
IT.LB.K_URINEKURINE

input/odm.csv

Edit
29 rows
input/odm.csv
StudyOIDMetaDataVersionOIDSubjectKeyStudyEventOIDStudyEventRepeatKeyFormOIDFormRepeatKeyItemGroupOIDItemGroupRepeatKeyItemOIDValue
YAMAA-01MDV.1YAMAA-01-101SE.LB1FO.LB1IG.LB1IT.LB.LBDTC2026-01-05
YAMAA-01MDV.1YAMAA-01-101SE.LB1FO.LB1IG.LB1IT.LB.ALT_SERUM32
YAMAA-01MDV.1YAMAA-01-101SE.LB1FO.LB1IG.LB2IT.LB.LBDTC2026-01-10
YAMAA-01MDV.1YAMAA-01-101SE.LB1FO.LB1IG.LB2IT.LB.ALT_SERUM35
YAMAA-01MDV.1YAMAA-01-101SE.LB1FO.LB1IG.LB3IT.LB.LBDTC2026-01-14
YAMAA-01MDV.1YAMAA-01-101SE.LB1FO.LB1IG.LB3IT.LB.ALT_SERUM—
YAMAA-01MDV.1YAMAA-01-101SE.LB1FO.LB1IG.LB3IT.LB.LBSTATNOT DONE
YAMAA-01MDV.1YAMAA-01-101SE.LB1FO.LB1IG.LB4IT.LB.LBDTC2026-01-15
YAMAA-01MDV.1YAMAA-01-101SE.LB1FO.LB1IG.LB4IT.LB.ALT_SERUM38
YAMAA-01MDV.1YAMAA-01-101SE.LB1FO.LB1IG.LB5IT.LB.LBDTC2026-01-20
YAMAA-01MDV.1YAMAA-01-101SE.LB1FO.LB1IG.LB5IT.LB.ALT_SERUM40
YAMAA-01MDV.1YAMAA-01-101SE.LB1FO.LB1IG.LB6IT.LB.LBDTC2026-01-08
YAMAA-01MDV.1YAMAA-01-101SE.LB1FO.LB1IG.LB6IT.LB.GLUC_SERUM5.1
YAMAA-01MDV.1YAMAA-01-101SE.LB1FO.LB1IG.LB7IT.LB.LBDTC2026-01-16
YAMAA-01MDV.1YAMAA-01-101SE.LB1FO.LB1IG.LB7IT.LB.GLUC_SERUM5.4
YAMAA-01MDV.1YAMAA-01-101SE.LB1FO.LB1IG.LB8IT.LB.LBDTC2026-01-09
YAMAA-01MDV.1YAMAA-01-101SE.LB1FO.LB1IG.LB8IT.LB.K_SERUM4.2
YAMAA-01MDV.1YAMAA-01-101SE.LB1FO.LB1IG.LB9IT.LB.LBDTC2026-01-18
YAMAA-01MDV.1YAMAA-01-101SE.LB1FO.LB1IG.LB9IT.LB.K_SERUM4.5
YAMAA-01MDV.1YAMAA-01-101SE.LB1FO.LB1IG.LB10IT.LB.LBDTC2026-01-12
YAMAA-01MDV.1YAMAA-01-101SE.LB1FO.LB1IG.LB10IT.LB.K_URINE60
YAMAA-01MDV.1YAMAA-01-101SE.LB1FO.LB1IG.LB11IT.LB.LBDTC2026-01-14
YAMAA-01MDV.1YAMAA-01-101SE.LB1FO.LB1IG.LB11IT.LB.K_URINE62
YAMAA-01MDV.1YAMAA-01-102SE.LB1FO.LB1IG.LB12IT.LB.LBDTC2026-02-01
YAMAA-01MDV.1YAMAA-01-102SE.LB1FO.LB1IG.LB12IT.LB.ALT_SERUM30
YAMAA-01MDV.1YAMAA-01-102SE.LB1FO.LB1IG.LB13IT.LB.LBDTC2026-02-10
YAMAA-01MDV.1YAMAA-01-102SE.LB1FO.LB1IG.LB13IT.LB.ALT_SERUM33
YAMAA-01MDV.1YAMAA-01-102SE.LB1FO.LB1IG.LB14IT.LB.LBDTC2026-02-10
YAMAA-01MDV.1YAMAA-01-102SE.LB1FO.LB1IG.LB14IT.LB.ALT_SERUM34

Expected output

Under review
14 expected rows

expected/lb.csv

Edit
14 rows
expected/lb.csv
DOMAINSTUDYIDUSUBJIDLBSEQLBTESTCDLBSPECLBORRESLBDTCLBSTATLBLOBXFL
LBYAMAA-011ALTSERUM322026-01-05——
LBYAMAA-012ALTSERUM352026-01-10——
LBYAMAA-013ALTSERUM—2026-01-14NOT DONE—
LBYAMAA-014ALTSERUM382026-01-15—Y
LBYAMAA-015ALTSERUM402026-01-20——
LBYAMAA-016GLUCSERUM5.12026-01-08—Y
LBYAMAA-017GLUCSERUM5.42026-01-16——
LBYAMAA-018KSERUM4.22026-01-09—Y
LBYAMAA-019KSERUM4.52026-01-18——
LBYAMAA-0110KURINE602026-01-12——
LBYAMAA-0111KURINE622026-01-14—Y
LBYAMAA-0112ALTSERUM302026-02-01——
LBYAMAA-0113ALTSERUM332026-02-10——
LBYAMAA-0114ALTSERUM342026-02-10—Y
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

Variable NameVariable LabelTypeLengthControlled Terms or FormatOriginCoreConversion DefinitionVariable TypeVariable OrderComments for Define
DOMAINDomain AbbreviationCharAssignedSet constant value "LB".SDTM1
STUDYIDStudy IdentifierCharCollectedCopy value from ODM.StudyOID.SDTM2
USUBJIDUnique Subject IdentifierCharCollectedCopy value from ODM.SubjectKey.SDTM3
LBSEQSequence NumberNumCollectedCopy value from ODM.ItemGroupRepeatKey.SDTM4
LBTESTCDLab Test or Examination Short NameCharDerivedSet per constructed row; see the Row construction sheet.SDTM5
LBSPECSpecimen Material TypeCharDerivedSet per constructed row; see the Row construction sheet.SDTM6
LBORRESResult or Finding in Original UnitsCharDerivedSet per constructed row; see the Row construction sheet.SDTM7
LBDTCDate/Time of Specimen CollectionCharISO 8601CollectedRead collected ODM item IT.LB.LBDTC; no identified record yields blank.SDTM8
LBSTATCompletion StatusCharCollectedRead collected ODM item IT.LB.LBSTAT; no identified record yields blank.SDTM9
LBLOBXFLLast Observation Before Exposure FlagCharDerived"Y" when LOBXRNK = 1; blank otherwise.SDTM10
TemplateInclude whenLBTESTCDLBSPECLBORRES
lb_resultLBTESTCD IS NOT NULLCopy LBTESTCD from the LB_MAPPING record whose ItemOID equals ODM.ItemOID, and no match yields blankCopy LBSPEC from the LB_MAPPING record whose ItemOID equals ODM.ItemOID, and no match yields blankAggregate ONLY(ODM.Value) over records matching on the shared output keys
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/sdtm-lb-last-observation-before-exposure/full.md

Edit
31 lines

Following CDISC SDTM standards, use the provided ODM, DM, and LB_MAPPING datasets to create an LB dataset with one record per collected laboratory result.

The output dataset should contain the following columns in this order: DOMAIN, STUDYID, USUBJID, LBSEQ, LBTESTCD, LBSPEC, LBORRES, LBDTC, LBSTAT, LBLOBXFL

STUDYID is the ODM StudyOID and USUBJID is the SubjectKey, each as given.

LBSEQ is the ItemGroupRepeatKey of the item group that holds the result, so it runs across the study rather than restarting for each subject. LBTESTCD is the test code from the item dictionary, and LBSPEC the specimen from the same entry; a test measured in more than one specimen is flagged separately per specimen. LBORRES is the result as collected, and has no value on records that were not done. LBDTC is the collection date as collected. LBSTAT is NOT DONE on records without a result.

LBLOBXFL is Y on the latest record with a result whose collection date falls on or before the subject's reference start date, within each subject, test, and specimen; it has no value on every other record. Records without a result never carry the flag, even when they carry the latest date. A subject with no reference start date carries the flag on the latest record with a result.

Dates compare at day precision, so a record collected on the day of first exposure still qualifies; of two results collected on the same date, the one with the higher sequence number is flagged.

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

prompts/sdtm-lb-last-observation-before-exposure/conventions.md

Edit
14 lines

Following CDISC SDTM standards, use the provided ODM, DM, and LB_MAPPING datasets to create an LB dataset with one record per collected laboratory result.

The output dataset should contain the following columns in this order: DOMAIN, STUDYID, USUBJID, LBSEQ, LBTESTCD, LBSPEC, LBORRES, LBDTC, LBSTAT, LBLOBXFL

LBSTAT is NOT DONE or has no value.

LBLOBXFL is Y or has no value.

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

prompts/sdtm-lb-last-observation-before-exposure/brief.md

Edit
10 lines

Following CDISC SDTM standards, use the provided ODM, DM, and LB_MAPPING datasets to create an LB dataset with one record per collected laboratory result.

The output dataset should contain the following columns in this order: DOMAIN, STUDYID, USUBJID, LBSEQ, LBTESTCD, LBSPEC, LBORRES, LBDTC, LBSTAT, LBLOBXFL

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

yamaa code

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

run.R

Edit
4 lines
library(yamaa)lb <- yamaa_domain("spec.yaml")$outputlb

run.py

Edit
4 lines
import yamaalb = yamaa.yamaa_domain("spec.yaml").outputlb

Solution without yamaa

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

solutions/sdtm-lb-last-observation-before-exposure/result.R

Edit
88 lines
# Reference solution for the yamaa benchmark sdtm-lb-last-observation-before-exposure (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(purrr)odm <- read_csv(  "/app/input/odm.csv",  col_types = cols(.default = col_character())) |>  mutate(Value = na_if(Value, ""))dm <- read_csv(  "/app/input/dm.csv",  col_types = cols(.default = col_character())) |>  mutate(RFSTDTC = na_if(RFSTDTC, ""))mapping <- read_csv(  "/app/input/lb_mapping.csv",  col_types = cols(.default = col_character()))groups <- odm |>  distinct(StudyOID, SubjectKey, ItemGroupRepeatKey)one_group <- function(study, subj, igrep) {  sub <- odm |>    filter(SubjectKey == subj, ItemGroupRepeatKey == igrep)  get <- function(oid) {    hit <- sub |> filter(ItemOID == oid)    if (nrow(hit) == 0) return(NA_character_)    hit$Value[[1]]  }  lbdtc <- get("IT.LB.LBDTC")  found <- mapping |>    filter(ItemOID %in% sub$ItemOID) |>    slice_head(n = 1)  if (nrow(found) == 0) return(tibble())  raw <- get(found$ItemOID[[1]])  has_result <- !is.na(raw)  tibble(    DOMAIN = "LB",    STUDYID = study,    USUBJID = subj,    LBSEQ = as.integer(igrep),    LBTESTCD = found$LBTESTCD[[1]],    LBSPEC = found$LBSPEC[[1]],    LBORRES = raw,    LBDTC = lbdtc,    LBSTAT = if_else(has_result, NA_character_, "NOT DONE"),    HAS = has_result  )}lb <- pmap_dfr(  list(groups$StudyOID, groups$SubjectKey, groups$ItemGroupRepeatKey),  one_group)flags <- lb |>  filter(HAS, !is.na(LBDTC)) |>  left_join(dm |> select(USUBJID, RFSTDTC), by = "USUBJID") |>  mutate(DAYDATE = substr(LBDTC, 1, 10), REFDAY = substr(RFSTDTC, 1, 10)) |>  filter(is.na(REFDAY) | DAYDATE <= REFDAY) |>  arrange(USUBJID, LBTESTCD, LBSPEC, DAYDATE, LBSEQ) |>  group_by(USUBJID, LBTESTCD, LBSPEC) |>  slice_tail(n = 1) |>  ungroup() |>  transmute(USUBJID, LBTESTCD, LBSPEC, FLAGSEQ = LBSEQ)lb <- lb |>  left_join(flags, by = c("USUBJID", "LBTESTCD", "LBSPEC")) |>  mutate(    LBLOBXFL = if_else(HAS & !is.na(FLAGSEQ) & LBSEQ == FLAGSEQ, "Y", NA_character_)  ) |>  arrange(STUDYID, USUBJID, LBSEQ) |>  select(    DOMAIN, STUDYID, USUBJID, LBSEQ, LBTESTCD, LBSPEC, LBORRES,    LBDTC, LBSTAT, LBLOBXFL  )dir.create("/app/output", showWarnings = FALSE)write_csv(lb, "/app/output/lb.csv", na = "")

solutions/sdtm-lb-last-observation-before-exposure/result.py

Edit
110 lines
# Reference solution for the yamaa benchmark sdtm-lb-last-observation-before-exposure (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 plodm = pl.read_csv("/app/input/odm.csv", infer_schema=False)dm = pl.read_csv("/app/input/dm.csv", infer_schema=False)mapping = pl.read_csv("/app/input/lb_mapping.csv", infer_schema=False)ref_of = {    r["USUBJID"]: (r["RFSTDTC"] if r["RFSTDTC"] not in (None, "") else None)    for r in dm.to_dicts()}map_of = {    r["ItemOID"]: (r["LBTESTCD"], r["LBSPEC"]) for r in mapping.to_dicts()}study_of = {}groups = {}for r in odm.to_dicts():    study_of[r["SubjectKey"]] = r["StudyOID"]    key = (r["SubjectKey"], r["ItemGroupRepeatKey"])    groups.setdefault(key, {})[r["ItemOID"]] = r["Value"]rows = []for (subj, repkey), items in groups.items():    lbdtc = items.get("IT.LB.LBDTC")    lbdtc = lbdtc if lbdtc not in (None, "") else None    # The test item in this group, via the item dictionary.    found = None    for oid, (code, spec) in map_of.items():        if oid in items:            found = (oid, code, spec)            break    if found is None:        continue    oid, code, spec = found    raw = items.get(oid)    has_result = raw is not None and raw != ""    lbstat = items.get("IT.LB.LBSTAT")    rows.append(        {            "DOMAIN": "LB",            "STUDYID": study_of[subj],            "USUBJID": subj,            "LBSEQ": int(repkey),            "LBTESTCD": code,            "LBSPEC": spec,            "LBORRES": raw if has_result else None,            "LBDTC": lbdtc,            "LBSTAT": "NOT DONE" if not has_result else None,            "_HAS": has_result,        }    )# Latest record with a result on or before the reference start date,# per subject, test, and specimen; ties go to the higher sequence number.flag_keys = {}for row in sorted(rows, key=lambda r: ((r["LBDTC"] or "")[:10], r["LBSEQ"])):    if not row["_HAS"] or row["LBDTC"] is None:        continue    ref = ref_of.get(row["USUBJID"])    if ref is not None and row["LBDTC"][:10] > ref[:10]:        continue    flag_keys[(row["USUBJID"], row["LBTESTCD"], row["LBSPEC"])] = row["LBSEQ"]for row in rows:    key = (row["USUBJID"], row["LBTESTCD"], row["LBSPEC"])    row["LBLOBXFL"] = (        "Y" if row["_HAS"] and flag_keys.get(key) == row["LBSEQ"] else None    )    del row["_HAS"]lb = (    pl.DataFrame(        rows,        schema={            "DOMAIN": pl.String,            "STUDYID": pl.String,            "USUBJID": pl.String,            "LBSEQ": pl.Int64,            "LBTESTCD": pl.String,            "LBSPEC": pl.String,            "LBORRES": pl.String,            "LBDTC": pl.String,            "LBSTAT": pl.String,            "LBLOBXFL": pl.String,        },    )    .sort(["STUDYID", "USUBJID", "LBSEQ"])    .select(        "DOMAIN",        "STUDYID",        "USUBJID",        "LBSEQ",        "LBTESTCD",        "LBSPEC",        "LBORRES",        "LBDTC",        "LBSTAT",        "LBLOBXFL",    ))Path("/app/output").mkdir(parents=True, exist_ok=True)lb.write_csv("/app/output/lb.csv")

solutions/sdtm-lb-last-observation-before-exposure/result.sas

Edit
48 lines
/* opensas reference solution for the yamaa benchmark sdtm-lb-last-observation-before-exposure.   Reads the benchmark inputs and derives the requested output.   Execute with the existing opensas runtime: opensas /app/output/result.sas. */data dm;  length STUDYID USUBJID RFSTDTC $1024;  infile "/app/input/dm.csv" dsd dlm="," firstobs=2 truncover lrecl=32767;  input STUDYID : $char1024. USUBJID : $char1024. RFSTDTC : $char1024.;run;data lb_mapping;  length ItemOID LBTESTCD LBSPEC $1024;  infile "/app/input/lb_mapping.csv" dsd dlm="," firstobs=2 truncover lrecl=32767;  input ItemOID : $char1024. LBTESTCD : $char1024. LBSPEC : $char1024.;run;data odm;  length StudyOID MetaDataVersionOID SubjectKey StudyEventOID StudyEventRepeatKey FormOID FormRepeatKey ItemGroupOID ItemGroupRepeatKey ItemOID Value $1024;  infile "/app/input/odm.csv" dsd dlm="," firstobs=2 truncover lrecl=32767;  input StudyOID : $char1024. MetaDataVersionOID : $char1024. SubjectKey : $char1024. StudyEventOID : $char1024. StudyEventRepeatKey : $char1024. FormOID : $char1024. FormRepeatKey : $char1024. ItemGroupOID : $char1024. ItemGroupRepeatKey : $char1024. ItemOID : $char1024. Value : $char1024.;run;proc sort data=odm out=ordered; by StudyOID SubjectKey StudyEventOID StudyEventRepeatKey FormOID FormRepeatKey ItemGroupRepeatKey; run;data dates;  length LBDTC LBSTAT $1024;  retain LBDTC LBSTAT;  set ordered;  by StudyOID SubjectKey StudyEventOID StudyEventRepeatKey FormOID FormRepeatKey ItemGroupRepeatKey;  if first.ItemGroupRepeatKey then do;    LBDTC=''; LBSTAT='';  end;    if ItemOID='IT.LB.LBDTC' then LBDTC=Value;  if ItemOID='IT.LB.LBSTAT' then LBSTAT=Value;  if last.ItemGroupRepeatKey then output;run;proc sql;create table joined as select a.*,b.LBDTC,b.LBSTAT,c.LBTESTCD,c.LBSPEC,d.RFSTDTC from odm a inner join dates b on a.StudyOID=b.StudyOID and a.SubjectKey=b.SubjectKey and a.StudyEventOID=b.StudyEventOID and a.StudyEventRepeatKey=b.StudyEventRepeatKey and a.FormOID=b.FormOID and a.FormRepeatKey=b.FormRepeatKey and a.ItemGroupRepeatKey=b.ItemGroupRepeatKey inner join lb_mapping c on a.ItemOID=c.ItemOID left join dm d on a.StudyOID=d.STUDYID and a.SubjectKey=d.USUBJID; quit;data collected; set joined; length DOMAIN $2 STUDYID USUBJID LBORRES DAYDATE REFDAY $1024; DOMAIN='LB'; STUDYID=StudyOID; USUBJID=SubjectKey; LBSEQ=input(ItemGroupRepeatKey,best32.); LBORRES=Value;if missing(Value) then LBSTAT='NOT DONE'; if LBSTAT='NOT DONE' then LBORRES=''; DAYDATE=''; REFDAY=''; if lengthn(LBDTC)>=10 then DAYDATE=substr(LBDTC,1,10); if lengthn(RFSTDTC)>=10 then REFDAY=substr(RFSTDTC,1,10); run;data eligible; set collected; if not missing(LBORRES) and not missing(DAYDATE) and (missing(REFDAY) or DAYDATE<=REFDAY); run;proc sort data=eligible; by STUDYID USUBJID LBTESTCD LBSPEC descending DAYDATE descending LBSEQ; run;data flagged; set eligible; by STUDYID USUBJID LBTESTCD LBSPEC; if first.LBSPEC; length LBLOBXFL $1; LBLOBXFL='Y'; run;proc sql; create table result as select a.*,b.LBLOBXFL from collected a left join flagged b on a.STUDYID=b.STUDYID and a.USUBJID=b.USUBJID and a.LBSEQ=b.LBSEQ and a.LBTESTCD=b.LBTESTCD and a.LBSPEC=b.LBSPEC; quit;proc sql;  create table final as select DOMAIN, STUDYID, USUBJID, LBSEQ, LBTESTCD, LBSPEC, LBORRES, LBDTC, LBSTAT, LBLOBXFL from result;quit;proc export data=final outfile="/app/output/lb.csv" dbms=csv replace; run;