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: build a laboratory (LB) basic data structure (BDS)
analysis dataset for alanine aminotransferase (ALT) and
aspartate aminotransferase (AST): flag each subject's baseline
record (ABLFL), carry its value (BASE), compute change
(CHG) and percent change (PCHG), and add one ALT record
converted to International System of Units (SI) (ALTSI),
alongside each subject's treatment start date (TRTSDT) and
actual treatment (TRT01A).
Input: collected ALT and AST results with collection dates, numeric results, and units, plus subject-level treatment start dates and actual treatments.
Variables:
ADTis the collection date of the result.TRTSDTis the subject's treatment start date.TRT01Ais the subject's actual treatment.AVALis the collected numeric result, or the result times 0.0167 on the SI record.AVALUis the collected unit, orukat/Lon the SI record.ABLFLisYon the latest record on or before the treatment start date for each subject and parameter; blank otherwise.BASEis theAVALof the flagged baseline record, repeated on every record for the same subject and parameter.CHGisAVALminusBASE.PCHGis 100 timesCHGdivided byBASE; empty when the baseline value is zero, since the percentage is undefined.
Note: a collected result with no numeric value produces no record. A subject with no collected results has no records: the treatment dates enrich records that already exist and never add one. A subject with a single collected result still gets a baseline flag, and a result collected on the treatment start date itself counts as baseline.
Inputs
Under review2 source filesinput/adsl.csv
Edit6 rows| STUDYID | USUBJID | TRTSDT | TRT01A |
|---|---|---|---|
| YAMAA-01 | 2025-01-02 | Study Drug 50 mg | |
| YAMAA-01 | 2025-01-02 | Study Drug 100 mg | |
| YAMAA-01 | 2025-01-02 | Placebo | |
| YAMAA-01 | 2025-01-02 | Placebo | |
| YAMAA-01 | 2025-01-02 | Placebo | |
| YAMAA-01 | 2025-01-02 | Study Drug 50 mg |
input/lb.csv
Edit12 rows| STUDYID | USUBJID | LBTESTCD | LBTEST | LBDTC | LBSTRESN | LBSTRESU |
|---|---|---|---|---|---|---|
| YAMAA-01 | ALT | Alanine Aminotransferase | 2025-01-01 | 10 | U/L | |
| YAMAA-01 | ALT | Alanine Aminotransferase | 2025-01-08 | 15 | U/L | |
| YAMAA-01 | AST | Aspartate Aminotransferase | 2025-01-01 | 20 | U/L | |
| YAMAA-01 | AST | Aspartate Aminotransferase | 2025-01-08 | 18 | U/L | |
| YAMAA-01 | ALT | Alanine Aminotransferase | 2025-01-01 | 8 | U/L | |
| YAMAA-01 | ALT | Alanine Aminotransferase | 2025-01-08 | 12 | U/L | |
| YAMAA-01 | ALT | Alanine Aminotransferase | 2025-01-01 | 0 | U/L | |
| YAMAA-01 | ALT | Alanine Aminotransferase | 2025-01-08 | 5 | U/L | |
| YAMAA-01 | ALT | Alanine Aminotransferase | 2025-01-15 | — | U/L | |
| YAMAA-01 | ALT | Alanine Aminotransferase | 2024-12-20 | 22 | U/L | |
| YAMAA-01 | ALT | Alanine Aminotransferase | 2025-01-02 | 30 | U/L | |
| YAMAA-01 | ALT | Alanine Aminotransferase | 2025-01-09 | 36 | U/L |
Expected output
Under review20 expected rowsexpected/adlb.csv
Edit20 rows| STUDYID | USUBJID | PARAMCD | PARAM | ADT | TRTSDT | TRT01A | AVAL | AVALU | ABLFL | BASE | CHG | PCHG | ASEQ |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| YAMAA-01 | ALT | Alanine Aminotransferase | 2025-01-01 | 2025-01-02 | Study Drug 50 mg | 10 | U/L | Y | 10 | 0 | 0 | 1 | |
| YAMAA-01 | ALT | Alanine Aminotransferase | 2025-01-08 | 2025-01-02 | Study Drug 50 mg | 15 | U/L | — | 10 | 5 | 50 | 2 | |
| YAMAA-01 | ALT | Alanine Aminotransferase | 2025-01-01 | 2025-01-02 | Study Drug 100 mg | 8 | U/L | Y | 8 | 0 | 0 | 1 | |
| YAMAA-01 | ALT | Alanine Aminotransferase | 2025-01-08 | 2025-01-02 | Study Drug 100 mg | 12 | U/L | — | 8 | 4 | 50 | 2 | |
| YAMAA-01 | ALT | Alanine Aminotransferase | 2025-01-01 | 2025-01-02 | Placebo | 0 | U/L | Y | 0 | 0 | — | 1 | |
| YAMAA-01 | ALT | Alanine Aminotransferase | 2025-01-08 | 2025-01-02 | Placebo | 5 | U/L | — | 0 | 5 | — | 2 | |
| YAMAA-01 | ALT | Alanine Aminotransferase | 2024-12-20 | 2025-01-02 | Placebo | 22 | U/L | Y | 22 | 0 | 0 | 1 | |
| YAMAA-01 | ALT | Alanine Aminotransferase | 2025-01-02 | 2025-01-02 | Study Drug 50 mg | 30 | U/L | Y | 30 | 0 | 0 | 1 | |
| YAMAA-01 | ALT | Alanine Aminotransferase | 2025-01-09 | 2025-01-02 | Study Drug 50 mg | 36 | U/L | — | 30 | 6 | 20 | 2 | |
| YAMAA-01 | ALTSI | Alanine Aminotransferase (SI) | 2025-01-01 | 2025-01-02 | Study Drug 50 mg | 0.16699999999999998 | ukat/L | Y | 0.16699999999999998 | 0 | 0 | 3 | |
| YAMAA-01 | ALTSI | Alanine Aminotransferase (SI) | 2025-01-08 | 2025-01-02 | Study Drug 50 mg | 0.2505 | ukat/L | — | 0.16699999999999998 | 0.08350000000000002 | 50.000000000000014 | 4 | |
| YAMAA-01 | ALTSI | Alanine Aminotransferase (SI) | 2025-01-01 | 2025-01-02 | Study Drug 100 mg | 0.1336 | ukat/L | Y | 0.1336 | 0 | 0 | 3 | |
| YAMAA-01 | ALTSI | Alanine Aminotransferase (SI) | 2025-01-08 | 2025-01-02 | Study Drug 100 mg | 0.2004 | ukat/L | — | 0.1336 | 0.0668 | 50 | 4 | |
| YAMAA-01 | ALTSI | Alanine Aminotransferase (SI) | 2025-01-01 | 2025-01-02 | Placebo | 0 | ukat/L | Y | 0 | 0 | — | 3 | |
| YAMAA-01 | ALTSI | Alanine Aminotransferase (SI) | 2025-01-08 | 2025-01-02 | Placebo | 0.08349999999999999 | ukat/L | — | 0 | 0.08349999999999999 | — | 4 | |
| YAMAA-01 | ALTSI | Alanine Aminotransferase (SI) | 2024-12-20 | 2025-01-02 | Placebo | 0.3674 | ukat/L | Y | 0.3674 | 0 | 0 | 2 | |
| YAMAA-01 | ALTSI | Alanine Aminotransferase (SI) | 2025-01-02 | 2025-01-02 | Study Drug 50 mg | 0.501 | ukat/L | Y | 0.501 | 0 | 0 | 3 | |
| YAMAA-01 | ALTSI | Alanine Aminotransferase (SI) | 2025-01-09 | 2025-01-02 | Study Drug 50 mg | 0.6012 | ukat/L | — | 0.501 | 0.10019999999999996 | 19.999999999999993 | 4 | |
| YAMAA-01 | AST | Aspartate Aminotransferase | 2025-01-01 | 2025-01-02 | Study Drug 50 mg | 20 | U/L | Y | 20 | 0 | 0 | 5 | |
| YAMAA-01 | AST | Aspartate Aminotransferase | 2025-01-08 | 2025-01-02 | Study Drug 50 mg | 18 | U/L | — | 20 | -2 | -10 | 6 |
Human review and assessment
| 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 | PARAMCD | Parameter Code | character | Set per constructed row; see the Row construction sheet. | Derived | ||
| ADLB | PARAM | Parameter | character | Set per constructed row; see the Row construction sheet. | Derived | ||
| ADLB | ADT | Analysis Date | numeric | ISO 8601 | Copy value from LB.LBDTC. | Predecessor | |
| ADLB | TRTSDT | Date of First Exposure to Treatment | numeric | ISO 8601 | Copy value from ADSL.TRTSDT. | Predecessor | |
| ADLB | TRT01A | Actual Treatment for Period 01 | character | Copy value from ADSL.TRT01A. | Predecessor | ||
| ADLB | AVAL | Analysis Value | numeric | Set per constructed row; see the Row construction sheet. | Derived | ||
| ADLB | AVALU | Analysis Value Unit | character | Set per constructed row; see the Row construction sheet. | Derived | ||
| ADLB | ABLFL | Baseline Record Flag | character | "Y" for the last record with ADT on or before TRTSDT and a non-missing AVAL within each group of STUDYID, USUBJID, PARAMCD, ordered by ADT; blank otherwise. | Derived | ||
| ADLB | BASE | Baseline Value | numeric | Aggregate ONLY(AVAL) over records grouped by STUDYID, USUBJID, PARAMCD, matching on the shared output keys, where ABLFL = 'Y'. | Derived | ||
| ADLB | CHG | Change from Baseline | numeric | Compute AVAL - BASE. | Derived | ||
| ADLB | PCHG | Percent Change from Baseline | numeric | Compute 100 * CHG / NULLIF(BASE, 0). | Derived | ||
| ADLB | ASEQ | Analysis Sequence Number | numeric | Row number within each group of STUDYID, USUBJID, ordered by PARAMCD then ADT. | Derived |
| Template | Include when | PARAMCD | PARAM | AVAL | AVALU |
|---|---|---|---|---|---|
| alt | LB.LBTESTCD = 'ALT' AND LB.LBSTRESN IS NOT NULL | Constant "ALT" | Constant "Alanine Aminotransferase" | Copy LB.LBSTRESN | Copy LB.LBSTRESU |
| alt_si | LB.LBTESTCD = 'ALT' AND LB.LBSTRESN IS NOT NULL | Constant "ALTSI" | Constant "Alanine Aminotransferase (SI)" | Compute LB.LBSTRESN * 0.0167 | Constant "ukat/L" |
| ast | LB.LBTESTCD = 'AST' AND LB.LBSTRESN IS NOT NULL | Constant "AST" | Constant "Aspartate Aminotransferase" | Copy LB.LBSTRESN | Copy LB.LBSTRESU |
| 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/adam-adlb-bds/full.md
Edit32 linesFollowing CDISC ADaM standards, use the provided ADSL and LB datasets to create an ADLB dataset with one record per subject per parameter per collection date.
The output dataset should contain the following columns in this order: STUDYID, USUBJID, PARAMCD, PARAM, ADT, TRTSDT, TRT01A, AVAL, AVALU, ABLFL, BASE, CHG, PCHG, ASEQ
The output holds one record for each collected ALT or AST result that has a numeric value, and one further record for each such ALT result converted to SI units. A collected result with no numeric value produces no record. PARAMCD is "ALT" and PARAM is "Alanine Aminotransferase" for a collected ALT result, "ALTSI" and "Alanine Aminotransferase (SI)" for a converted record, and "AST" and "Aspartate Aminotransferase" for a collected AST result. ADT is the collection date of the result. TRTSDT is the subject's treatment start date, and TRT01A is the subject's actual treatment. A subject with no collected results has no records: TRTSDT and TRT01A enrich records that already exist and never add one. AVAL is the collected numeric result, or the result times 0.0167 on the SI record. AVALU is the collected unit, or "ukat/L" on the SI record. ABLFL is "Y" on the latest record on or before the treatment start date for each subject and parameter, and has no value otherwise. A result collected on the treatment start date itself counts as baseline, and a subject with a single collected result for a parameter still gets a baseline flag. BASE is the AVAL of the flagged baseline record, repeated on every record for the same subject and parameter. CHG is AVAL minus BASE. PCHG is 100 times CHG divided by BASE, and has no value when BASE is zero. AVAL, CHG, and PCHG are not rounded. ASEQ numbers the records within each subject in order of PARAMCD and then ADT, starting at 1.
Read the source datasets from /app/input and save the completed dataset as /app/output/adlb.csv.
prompts/adam-adlb-bds/conventions.md
Edit15 linesFollowing CDISC ADaM standards, use the provided ADSL and LB datasets to create an ADLB dataset with one record per subject per parameter per collection date.
The output dataset should contain the following columns in this order: STUDYID, USUBJID, PARAMCD, PARAM, ADT, TRTSDT, TRT01A, AVAL, AVALU, ABLFL, BASE, CHG, PCHG, ASEQ
PARAMCD is "ALT" and PARAM is "Alanine Aminotransferase", PARAMCD is "ALTSI" and PARAM is "Alanine Aminotransferase (SI)", or PARAMCD is "AST" and PARAM is "Aspartate Aminotransferase". ABLFL is "Y" or has no value. AVAL, CHG, and PCHG are not rounded.
Read the source datasets from /app/input and save the completed dataset as /app/output/adlb.csv.
prompts/adam-adlb-bds/brief.md
Edit10 linesFollowing CDISC ADaM standards, use the provided ADSL and LB datasets to create an ADLB dataset with one record per subject per parameter per collection date.
The output dataset should contain the following columns in this order: STUDYID, USUBJID, PARAMCD, PARAM, ADT, TRTSDT, TRT01A, AVAL, AVALU, ABLFL, BASE, CHG, PCHG, ASEQ
Read the source datasets from /app/input and save the completed dataset as /app/output/adlb.csv.
R
Edit3 lineslibrary(yamaa)yamaa_spec("spec.yaml")$run()$outputPython
Edit3 linesimport yamaayamaa.spec("spec.yaml").run().outputsolutions/adam-adlb-bds/result.R
Edit113 lines# Reference solution for the yamaa benchmark adam-adlb-bds (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)adsl <- read_csv( "/app/input/adsl.csv", col_types = cols(TRTSDT = col_date(), .default = col_character()))lb <- read_csv( "/app/input/lb.csv", col_types = cols( LBDTC = col_date(), LBSTRESN = col_double(), .default = col_character() ))# One record per collected ALT/AST result; a collected result with no# numeric value produces no record.collected <- lb |> filter(LBTESTCD %in% c("ALT", "AST"), !is.na(LBSTRESN))# ALT and AST hold the collected result and unit; ALTSI holds the ALT# result times 0.0167 with unit ukat/L, one record for each ALT record.alt <- collected |> filter(LBTESTCD %in% "ALT") |> transmute( STUDYID, USUBJID, PARAMCD = "ALT", PARAM = "Alanine Aminotransferase", ADT = LBDTC, AVAL = LBSTRESN, AVALU = LBSTRESU )ast <- collected |> filter(LBTESTCD %in% "AST") |> transmute( STUDYID, USUBJID, PARAMCD = "AST", PARAM = "Aspartate Aminotransferase", ADT = LBDTC, AVAL = LBSTRESN, AVALU = LBSTRESU )altsi <- collected |> filter(LBTESTCD %in% "ALT") |> transmute( STUDYID, USUBJID, PARAMCD = "ALTSI", PARAM = "Alanine Aminotransferase (SI)", ADT = LBDTC, AVAL = LBSTRESN * 0.0167, AVALU = "ukat/L" )base <- bind_rows(alt, ast, altsi) |> left_join( adsl |> select(STUDYID, USUBJID, TRTSDT, TRT01A), by = c("STUDYID", "USUBJID") )# ABLFL is Y on the latest record on or before the treatment start date# for each subject and parameter, including the start date itself.baseline_dates <- base |> filter(ADT <= TRTSDT) |> group_by(STUDYID, USUBJID, PARAMCD) |> summarise(BASE_DT = max(ADT), .groups = "drop")with_flag <- base |> left_join(baseline_dates, by = c("STUDYID", "USUBJID", "PARAMCD")) |> mutate(ABLFL = if_else(!is.na(BASE_DT) & ADT == BASE_DT, "Y", NA_character_))# BASE repeats the flagged baseline value; CHG and PCHG follow, with PCHG# empty when the baseline is zero. Values are not rounded.baselines <- with_flag |> filter(ABLFL %in% "Y") |> select(STUDYID, USUBJID, PARAMCD, BASE = AVAL)adlb_flagged <- with_flag |> select(-BASE_DT) |> left_join(baselines, by = c("STUDYID", "USUBJID", "PARAMCD")) |> mutate( CHG = AVAL - BASE, PCHG = if_else( is.na(BASE) | BASE == 0, NA_real_, 100 * (AVAL - BASE) / BASE ) )# ASEQ numbers each subject's records from 1, ordered by PARAMCD (ALT,# then ALTSI, then AST) and then by ADT.param_order <- c("ALT" = 0L, "ALTSI" = 1L, "AST" = 2L)adlb <- adlb_flagged |> mutate(PARAM_ORDER = param_order[PARAMCD]) |> arrange(STUDYID, USUBJID, PARAM_ORDER, ADT) |> group_by(STUDYID, USUBJID) |> mutate(ASEQ = row_number()) |> ungroup() |> arrange(PARAM_ORDER, USUBJID, ADT) |> select( STUDYID, USUBJID, PARAMCD, PARAM, ADT, TRTSDT, TRT01A, AVAL, AVALU, ABLFL, BASE, CHG, PCHG, ASEQ )dir.create("/app/output", showWarnings = FALSE)write_csv(adlb, "/app/output/adlb.csv", na = "")solutions/adam-adlb-bds/result.py
Edit137 lines# Reference solution for the yamaa benchmark adam-adlb-bds (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.import csvfrom collections import OrderedDictINPUT_DIR = "/app/input"OUTPUT_DIR = "/app/output"def fmt(value): if value is None: return "" if isinstance(value, str): return value if value == int(value) and abs(value) < 1e15: return str(int(value)) return repr(value)def main(): adsl = {} with open(f"{INPUT_DIR}/adsl.csv", newline="") as f: for row in csv.DictReader(f): adsl[row["USUBJID"]] = row params = { "ALT": ("ALT", "Alanine Aminotransferase"), "AST": ("AST", "Aspartate Aminotransferase"), } records = [] with open(f"{INPUT_DIR}/lb.csv", newline="") as f: for row in csv.DictReader(f): testcd = row["LBTESTCD"] if testcd not in params: continue raw = (row["LBSTRESN"] or "").strip() if raw == "": continue try: aval = float(raw) except ValueError: continue subj = adsl.get(row["USUBJID"], {}) base_rec = { "STUDYID": row["STUDYID"], "USUBJID": row["USUBJID"], "ADT": row["LBDTC"], "TRTSDT": subj.get("TRTSDT", ""), "TRT01A": subj.get("TRT01A", ""), } paramcd, param = params[testcd] rec = dict(base_rec) rec.update({ "PARAMCD": paramcd, "PARAM": param, "AVAL": aval, "AVAL_TEXT": raw, "AVALU": row["LBSTRESU"], }) records.append(rec) if testcd == "ALT": si = dict(base_rec) si.update({ "PARAMCD": "ALTSI", "PARAM": "Alanine Aminotransferase (SI)", "AVAL": aval * 0.0167, "AVAL_TEXT": None, "AVALU": "ukat/L", }) records.append(si) # Baseline: latest record on or before TRTSDT per subject + parameter. groups = OrderedDict() for rec in records: groups.setdefault((rec["USUBJID"], rec["PARAMCD"]), []).append(rec) for key, grecs in groups.items(): baseline = None for rec in grecs: if rec["TRTSDT"] and rec["ADT"] <= rec["TRTSDT"]: if baseline is None or rec["ADT"] > baseline["ADT"]: baseline = rec for rec in grecs: rec["ABLFL"] = "Y" if rec is baseline else "" if baseline is None: rec["BASE"] = None rec["CHG"] = None rec["PCHG"] = None else: base = baseline["AVAL"] chg = rec["AVAL"] - base rec["BASE"] = base rec["CHG"] = chg rec["PCHG"] = None if base == 0 else 100.0 * chg / base records.sort(key=lambda r: (r["USUBJID"], r["PARAMCD"], r["ADT"])) by_subject = OrderedDict() for rec in records: by_subject.setdefault(rec["USUBJID"], []).append(rec) for subj, srecs in by_subject.items(): for i, rec in enumerate(srecs, start=1): rec["ASEQ"] = i columns = ["STUDYID", "USUBJID", "PARAMCD", "PARAM", "ADT", "TRTSDT", "TRT01A", "AVAL", "AVALU", "ABLFL", "BASE", "CHG", "PCHG", "ASEQ"] with open(f"{OUTPUT_DIR}/adlb.csv", "w", newline="") as f: writer = csv.writer(f) writer.writerow(columns) for rec in records: writer.writerow([ rec["STUDYID"], rec["USUBJID"], rec["PARAMCD"], rec["PARAM"], rec["ADT"], rec["TRTSDT"], rec["TRT01A"], rec["AVAL_TEXT"] if rec["AVAL_TEXT"] is not None else fmt(rec["AVAL"]), rec["AVALU"], rec["ABLFL"], fmt(rec["BASE"]), fmt(rec["CHG"]), fmt(rec["PCHG"]), rec["ASEQ"], ])if __name__ == "__main__": main()solutions/adam-adlb-bds/result.sas
Edit43 lines/* opensas reference solution for the yamaa benchmark adam-adlb-bds. Reads the benchmark inputs and derives the requested output. Execute with the existing opensas runtime: opensas /app/output/result.sas. */data adsl; length STUDYID USUBJID TRTSDT TRT01A $1024; infile "/app/input/adsl.csv" dsd dlm="," firstobs=2 truncover lrecl=32767; input STUDYID : $char1024. USUBJID : $char1024. TRTSDT : $char1024. TRT01A : $char1024.;run;data lb; length STUDYID USUBJID LBTESTCD LBTEST LBDTC LBSTRESU $1024; infile "/app/input/lb.csv" dsd dlm="," firstobs=2 truncover lrecl=32767; input STUDYID : $char1024. USUBJID : $char1024. LBTESTCD : $char1024. LBTEST : $char1024. LBDTC : $char1024. LBSTRESN LBSTRESU : $char1024.;run;data parameters; length PARAMCD $16 PARAM $40 ADT $10 AVALU $1024; set lb; if LBTESTCD in ('ALT','AST') and not missing(LBSTRESN); ADT=LBDTC; PARAMCD=LBTESTCD; AVAL=LBSTRESN; AVALU=LBSTRESU; if LBTESTCD='ALT' then PARAM='Alanine Aminotransferase'; else PARAM='Aspartate Aminotransferase'; output; if LBTESTCD='ALT' then do; PARAMCD='ALTSI'; PARAM='Alanine Aminotransferase (SI)'; AVAL=LBSTRESN*0.0167; AVALU='ukat/L'; output; end;run;proc sql; create table joined as select a.*,b.TRTSDT,b.TRT01A from parameters as a left join adsl as b on a.STUDYID=b.STUDYID and a.USUBJID=b.USUBJID; quit;proc sort data=joined(where=(ADT ne '' and TRTSDT ne '' and ADT<=TRTSDT)) out=candidates; by STUDYID USUBJID PARAMCD descending ADT; run;data baseline; set candidates; by STUDYID USUBJID PARAMCD; if first.PARAMCD; BASE=AVAL; keep STUDYID USUBJID PARAMCD ADT BASE; rename ADT=BASEDT; run;proc sql; create table combined as select a.*,b.BASE,b.BASEDT from joined as a left join baseline as b on a.STUDYID=b.STUDYID and a.USUBJID=b.USUBJID and a.PARAMCD=b.PARAMCD; quit;proc sort data=combined; by STUDYID USUBJID PARAMCD ADT; run;data result; length ABLFL $1; set combined; by STUDYID USUBJID; if first.USUBJID then ASEQ=0; ASEQ+1; if ADT=BASEDT and not missing(BASEDT) then ABLFL='Y'; CHG=AVAL-BASE; if not missing(BASE) and BASE ne 0 then PCHG=100*CHG/BASE;run;proc sql; create table final as select STUDYID, USUBJID, PARAMCD, PARAM, ADT, TRTSDT, TRT01A, AVAL, AVALU, ABLFL, BASE, CHG, PCHG, ASEQ from result;quit;proc export data=final outfile="/app/output/adlb.csv" dbms=csv replace; run;
yamaa