As a clinical trial statistician or programmer, answer three short questions in Your review: the task, the inputs and outputs, and the AI-assisted review. Agreeing with all three approves this benchmark; disagreeing with any needs a comment. Propose a fix with the Edit button on any source file, or add it to your comments.
We suggest spending no more than 5 minutes on a review. The other tabs beside Your review are background for assessment, not under review.
Summary
README.mdPublic entries: Python and R. Passing coverage requires an installed inventory.
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:
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 |
Human review and assessment
| 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.7 | 2026-10-20 | yamaa docs build | Read a specification in the 1.0 surface as its 0.5 counterpart; state that missing values stay missing where a mapping declares no missing handler, and leave out a declared missing answer that restates a handler's default | ||
| 1.6 | 2026-10-17 | yamaa docs build | Describe collected date parts written as ISO 8601 date text and times of day counted in seconds since midnight | ||
| 1.5 | 2026-10-17 | yamaa docs build | Name collected precision in words instead of letter codes; state imputation fallbacks, minimum source precision, bounds ignored outside the collected period, and invalid text with no handler as an error; describe date and datetime shifts, imputation flag codes, and partial text giving no date part | ||
| 1.4 | 2026-10-15 | yamaa docs build | State datetime precision codes through the hour and minute, and complete only the time parts a collected datetime lacks | ||
| 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
Edit30 linesFollowing CDISC SDTM standards, use the provided DM, LB_MAPPING, and ODM datasets to create an LB dataset with one record per laboratory result.
The output dataset should contain the following columns in this order: DOMAIN, STUDYID, USUBJID, LBSEQ, LBTESTCD, LBSPEC, LBORRES, LBDTC, LBSTAT, LBLOBXFL
DOMAIN is "LB". STUDYID is the study OID in ODM, as given, and USUBJID is the subject key in ODM, as given. LBSEQ is the item group repeat number of the result, as collected. LBTESTCD is the test code in LB_MAPPING for the result item, and LBSPEC is the specimen in LB_MAPPING for that item. LBTESTCD and LBSPEC together define the series within which the flag is assigned, and a test measured in more than one specimen is flagged separately for each specimen. LBORRES is the result as collected, and has no value on a record that was not done. LBDTC is the collection date as collected. LBSTAT is the completion status as collected, "NOT DONE" on a record without a result. LBLOBXFL is "Y" on the latest record with a result in the series whose collection date falls on or before the subject's reference start date in DM, and has no value on every other record. A record without a result never carries the flag, even when it carries 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 the reference start date still qualifies. Of two results collected on the same date, the one with the higher LBSEQ carries the flag.
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
Edit11 linesFollowing CDISC SDTM standards, use the provided DM, LB_MAPPING, and ODM datasets to create an LB dataset with one record per laboratory result.
The output dataset should contain the following columns in this order: DOMAIN, STUDYID, USUBJID, LBSEQ, LBTESTCD, LBSPEC, LBORRES, LBDTC, LBSTAT, LBLOBXFL
DOMAIN is "LB". 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
Edit9 linesFollowing CDISC SDTM standards, use the provided DM, LB_MAPPING, and ODM datasets to create an LB dataset with one record per 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.
R
Edit3 lineslibrary(yamaa)yamaa_spec("spec.yaml")$run()$outputPython
Edit3 linesimport yamaayamaa.spec("spec.yaml").run().outputsolutions/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
Edit137 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."""Build the LB dataset from DM, LB_MAPPING and ODM extracts.One output record per laboratory result item group in the ODM extract.LBLOBXFL flags the last observation with a result, within each(LBTESTCD, LBSPEC) series for a subject, whose collection date falls onor before the subject's reference start date (RFSTDTC in DM). A subjectwithout a reference start date has the flag on the latest record with aresult in the series."""import csvfrom datetime import dateINPUT_DIR = "/app/input"OUTPUT_FILE = "/app/output/lb.csv"COLUMNS = [ "DOMAIN", "STUDYID", "USUBJID", "LBSEQ", "LBTESTCD", "LBSPEC", "LBORRES", "LBDTC", "LBSTAT", "LBLOBXFL",]def read_csv(path): with open(path, newline="", encoding="utf-8") as handle: return list(csv.DictReader(handle))def day(text): """Parse an ISO date/datetime at day precision; None when blank.""" text = (text or "").strip() if not text: return None return date.fromisoformat(text[:10])def main(): dm = read_csv(f"{INPUT_DIR}/dm.csv") mapping = read_csv(f"{INPUT_DIR}/lb_mapping.csv") odm = read_csv(f"{INPUT_DIR}/odm.csv") ref_start = {} for row in dm: ref_start[row["USUBJID"]] = day(row["RFSTDTC"]) test_map = {row["ItemOID"]: (row["LBTESTCD"], row["LBSPEC"]) for row in mapping} # Group the ODM items into one record per item group occurrence, # keeping the collected order. groups = {} order = [] for row in odm: key = (row["StudyOID"], row["SubjectKey"], row["ItemGroupRepeatKey"]) if key not in groups: groups[key] = { "STUDYID": row["StudyOID"], "USUBJID": row["SubjectKey"], "LBSEQ": row["ItemGroupRepeatKey"], "items": {}, } order.append(key) groups[key]["items"][row["ItemOID"]] = row["Value"] records = [] for key in order: group = groups[key] items = group["items"] result_items = [oid for oid in items if oid in test_map] if not result_items: continue item_oid = result_items[0] testcd, spec = test_map[item_oid] result = (items.get(item_oid) or "").strip() stat = (items.get("IT.LB.LBSTAT") or "").strip() if not result: stat = stat or "NOT DONE" records.append( { "DOMAIN": "LB", "STUDYID": group["STUDYID"], "USUBJID": group["USUBJID"], "LBSEQ": group["LBSEQ"], "LBTESTCD": testcd, "LBSPEC": spec, "LBORRES": result, "LBDTC": (items.get("IT.LB.LBDTC") or "").strip(), "LBSTAT": stat, "LBLOBXFL": "", } ) # Assign the flag within each subject and (test, specimen) series. series = {} for idx, record in enumerate(records): key = (record["USUBJID"], record["LBTESTCD"], record["LBSPEC"]) series.setdefault(key, []).append(idx) for (usubjid, _testcd, _spec), idxs in series.items(): ref = ref_start.get(usubjid) candidates = [] for idx in idxs: record = records[idx] if not record["LBORRES"]: continue # a record without a result never carries the flag collected = day(record["LBDTC"]) if ref is not None and (collected is None or collected > ref): continue # collected after the reference start date candidates.append(idx) if not candidates: continue best = max( candidates, key=lambda i: (day(records[i]["LBDTC"]) or date.min, int(records[i]["LBSEQ"])), ) records[best]["LBLOBXFL"] = "Y" with open(OUTPUT_FILE, "w", newline="", encoding="utf-8") as handle: writer = csv.DictWriter(handle, fieldnames=COLUMNS) writer.writeheader() writer.writerows(records)if __name__ == "__main__": main()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