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 SDTM: 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: 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:
LBTESTCDis the test code from the item dictionary; together with the specimen it defines the series the flag is assigned within.LBSPECis the specimen from the item dictionary; a test measured in more than one specimen is flagged separately per specimen.LBORRESis the result as collected; missing on records that were not done.LBDTCis the collection date as collected.LBSTATis the completion status as collected;NOT DONEon records without a result.LBLOBXFLisYon 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 review3 source filesinput/dm.csv
Edit2 rows| STUDYID | USUBJID | RFSTDTC |
|---|---|---|
| YAMAA-01 | 2026-01-15 | |
| YAMAA-01 | — |
input/lb_mapping.csv
Edit4 rows| ItemOID | LBTESTCD | LBSPEC |
|---|---|---|
| IT.LB.ALT_SERUM | ALT | SERUM |
| IT.LB.GLUC_SERUM | GLUC | SERUM |
| IT.LB.K_SERUM | K | SERUM |
| IT.LB.K_URINE | K | URINE |
input/odm.csv
Edit29 rows| StudyOID | MetaDataVersionOID | SubjectKey | StudyEventOID | StudyEventRepeatKey | FormOID | FormRepeatKey | ItemGroupOID | ItemGroupRepeatKey | ItemOID | Value |
|---|---|---|---|---|---|---|---|---|---|---|
| YAMAA-01 | MDV.1 | YAMAA-01-101 | SE.LB | 1 | FO.LB | 1 | IG.LB | 1 | IT.LB.LBDTC | 2026-01-05 |
| YAMAA-01 | MDV.1 | YAMAA-01-101 | SE.LB | 1 | FO.LB | 1 | IG.LB | 1 | IT.LB.ALT_SERUM | 32 |
| YAMAA-01 | MDV.1 | YAMAA-01-101 | SE.LB | 1 | FO.LB | 1 | IG.LB | 2 | IT.LB.LBDTC | 2026-01-10 |
| YAMAA-01 | MDV.1 | YAMAA-01-101 | SE.LB | 1 | FO.LB | 1 | IG.LB | 2 | IT.LB.ALT_SERUM | 35 |
| YAMAA-01 | MDV.1 | YAMAA-01-101 | SE.LB | 1 | FO.LB | 1 | IG.LB | 3 | IT.LB.LBDTC | 2026-01-14 |
| YAMAA-01 | MDV.1 | YAMAA-01-101 | SE.LB | 1 | FO.LB | 1 | IG.LB | 3 | IT.LB.ALT_SERUM | — |
| YAMAA-01 | MDV.1 | YAMAA-01-101 | SE.LB | 1 | FO.LB | 1 | IG.LB | 3 | IT.LB.LBSTAT | NOT DONE |
| YAMAA-01 | MDV.1 | YAMAA-01-101 | SE.LB | 1 | FO.LB | 1 | IG.LB | 4 | IT.LB.LBDTC | 2026-01-15 |
| YAMAA-01 | MDV.1 | YAMAA-01-101 | SE.LB | 1 | FO.LB | 1 | IG.LB | 4 | IT.LB.ALT_SERUM | 38 |
| YAMAA-01 | MDV.1 | YAMAA-01-101 | SE.LB | 1 | FO.LB | 1 | IG.LB | 5 | IT.LB.LBDTC | 2026-01-20 |
| YAMAA-01 | MDV.1 | YAMAA-01-101 | SE.LB | 1 | FO.LB | 1 | IG.LB | 5 | IT.LB.ALT_SERUM | 40 |
| YAMAA-01 | MDV.1 | YAMAA-01-101 | SE.LB | 1 | FO.LB | 1 | IG.LB | 6 | IT.LB.LBDTC | 2026-01-08 |
| YAMAA-01 | MDV.1 | YAMAA-01-101 | SE.LB | 1 | FO.LB | 1 | IG.LB | 6 | IT.LB.GLUC_SERUM | 5.1 |
| YAMAA-01 | MDV.1 | YAMAA-01-101 | SE.LB | 1 | FO.LB | 1 | IG.LB | 7 | IT.LB.LBDTC | 2026-01-16 |
| YAMAA-01 | MDV.1 | YAMAA-01-101 | SE.LB | 1 | FO.LB | 1 | IG.LB | 7 | IT.LB.GLUC_SERUM | 5.4 |
| YAMAA-01 | MDV.1 | YAMAA-01-101 | SE.LB | 1 | FO.LB | 1 | IG.LB | 8 | IT.LB.LBDTC | 2026-01-09 |
| YAMAA-01 | MDV.1 | YAMAA-01-101 | SE.LB | 1 | FO.LB | 1 | IG.LB | 8 | IT.LB.K_SERUM | 4.2 |
| YAMAA-01 | MDV.1 | YAMAA-01-101 | SE.LB | 1 | FO.LB | 1 | IG.LB | 9 | IT.LB.LBDTC | 2026-01-18 |
| YAMAA-01 | MDV.1 | YAMAA-01-101 | SE.LB | 1 | FO.LB | 1 | IG.LB | 9 | IT.LB.K_SERUM | 4.5 |
| YAMAA-01 | MDV.1 | YAMAA-01-101 | SE.LB | 1 | FO.LB | 1 | IG.LB | 10 | IT.LB.LBDTC | 2026-01-12 |
| YAMAA-01 | MDV.1 | YAMAA-01-101 | SE.LB | 1 | FO.LB | 1 | IG.LB | 10 | IT.LB.K_URINE | 60 |
| YAMAA-01 | MDV.1 | YAMAA-01-101 | SE.LB | 1 | FO.LB | 1 | IG.LB | 11 | IT.LB.LBDTC | 2026-01-14 |
| YAMAA-01 | MDV.1 | YAMAA-01-101 | SE.LB | 1 | FO.LB | 1 | IG.LB | 11 | IT.LB.K_URINE | 62 |
| YAMAA-01 | MDV.1 | YAMAA-01-102 | SE.LB | 1 | FO.LB | 1 | IG.LB | 12 | IT.LB.LBDTC | 2026-02-01 |
| YAMAA-01 | MDV.1 | YAMAA-01-102 | SE.LB | 1 | FO.LB | 1 | IG.LB | 12 | IT.LB.ALT_SERUM | 30 |
| YAMAA-01 | MDV.1 | YAMAA-01-102 | SE.LB | 1 | FO.LB | 1 | IG.LB | 13 | IT.LB.LBDTC | 2026-02-10 |
| YAMAA-01 | MDV.1 | YAMAA-01-102 | SE.LB | 1 | FO.LB | 1 | IG.LB | 13 | IT.LB.ALT_SERUM | 33 |
| YAMAA-01 | MDV.1 | YAMAA-01-102 | SE.LB | 1 | FO.LB | 1 | IG.LB | 14 | IT.LB.LBDTC | 2026-02-10 |
| YAMAA-01 | MDV.1 | YAMAA-01-102 | SE.LB | 1 | FO.LB | 1 | IG.LB | 14 | IT.LB.ALT_SERUM | 34 |
Expected output
Under review14 expected rowsexpected/lb.csv
Edit14 rows| DOMAIN | STUDYID | USUBJID | LBSEQ | LBTESTCD | LBSPEC | LBORRES | LBDTC | LBSTAT | LBLOBXFL |
|---|---|---|---|---|---|---|---|---|---|
| LB | YAMAA-01 | 1 | ALT | SERUM | 32 | 2026-01-05 | — | — | |
| LB | YAMAA-01 | 2 | ALT | SERUM | 35 | 2026-01-10 | — | — | |
| LB | YAMAA-01 | 3 | ALT | SERUM | — | 2026-01-14 | NOT DONE | — | |
| LB | YAMAA-01 | 4 | ALT | SERUM | 38 | 2026-01-15 | — | Y | |
| LB | YAMAA-01 | 5 | ALT | SERUM | 40 | 2026-01-20 | — | — | |
| LB | YAMAA-01 | 6 | GLUC | SERUM | 5.1 | 2026-01-08 | — | Y | |
| LB | YAMAA-01 | 7 | GLUC | SERUM | 5.4 | 2026-01-16 | — | — | |
| LB | YAMAA-01 | 8 | K | SERUM | 4.2 | 2026-01-09 | — | Y | |
| LB | YAMAA-01 | 9 | K | SERUM | 4.5 | 2026-01-18 | — | — | |
| LB | YAMAA-01 | 10 | K | URINE | 60 | 2026-01-12 | — | — | |
| LB | YAMAA-01 | 11 | K | URINE | 62 | 2026-01-14 | — | Y | |
| LB | YAMAA-01 | 12 | ALT | SERUM | 30 | 2026-02-01 | — | — | |
| LB | YAMAA-01 | 13 | ALT | SERUM | 33 | 2026-02-10 | — | — | |
| LB | YAMAA-01 | 14 | ALT | SERUM | 34 | 2026-02-10 | — | Y |
Comments and assessment materials
| Variable Name | Variable Label | Type | Length | Controlled Terms or Format | Origin | Core | Conversion Definition | Variable Type | Variable Order | Comments for Define |
|---|---|---|---|---|---|---|---|---|---|---|
| DOMAIN | Domain Abbreviation | Char | Assigned | Set constant value "LB". | SDTM | 1 | ||||
| STUDYID | Study Identifier | Char | Collected | Copy value from ODM.StudyOID. | SDTM | 2 | ||||
| USUBJID | Unique Subject Identifier | Char | Collected | Copy value from ODM.SubjectKey. | SDTM | 3 | ||||
| LBSEQ | Sequence Number | Num | Collected | Copy value from ODM.ItemGroupRepeatKey. | SDTM | 4 | ||||
| LBTESTCD | Lab Test or Examination Short Name | Char | Derived | Set per constructed row; see the Row construction sheet. | SDTM | 5 | ||||
| LBSPEC | Specimen Material Type | Char | Derived | Set per constructed row; see the Row construction sheet. | SDTM | 6 | ||||
| LBORRES | Result or Finding in Original Units | Char | Derived | Set per constructed row; see the Row construction sheet. | SDTM | 7 | ||||
| LBDTC | Date/Time of Specimen Collection | Char | ISO 8601 | Collected | Read collected ODM item IT.LB.LBDTC; no identified record yields blank. | SDTM | 8 | |||
| LBSTAT | Completion Status | Char | Collected | Read collected ODM item IT.LB.LBSTAT; no identified record yields blank. | SDTM | 9 | ||||
| LBLOBXFL | Last Observation Before Exposure Flag | Char | Derived | "Y" when LOBXRNK = 1; blank otherwise. | SDTM | 10 |
| Template | Include when | LBTESTCD | LBSPEC | LBORRES |
|---|---|---|---|---|
| lb_result | LBTESTCD IS NOT NULL | Copy LBTESTCD from the LB_MAPPING record whose ItemOID equals ODM.ItemOID, and no match yields blank | Copy LBSPEC from the LB_MAPPING record whose ItemOID equals ODM.ItemOID, and no match yields blank | Aggregate ONLY(ODM.Value) over records matching on the shared output keys |
| 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/sdtm-lb-last-observation-before-exposure/full.md
Edit31 linesFollowing 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
Edit14 linesFollowing 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
Edit10 linesFollowing 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.
run.R
Edit4 lineslibrary(yamaa)lb <- yamaa_domain("spec.yaml")$outputlbrun.py
Edit4 linesimport yamaalb = yamaa.yamaa_domain("spec.yaml").outputlbsolutions/sdtm-lb-last-observation-before-exposure/result.R
Edit88 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
Edit110 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
Edit48 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;
yamaa
Comments
Signed in with GitHub; saved in repository Discussions