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: give every dose record and every pharmacokinetic (PK)
concentration record of a population PK dataset the body weight (WT)
and the serum creatinine (CREAT) that applied on its date, and the
creatinine clearance (CRCL) those two give.
Input: exposure (EX) records, one per administration, with the dose
(EXDOSE) and its date/time (EXSTDTC); PK concentration (PC) records
with the collection date/time (PCDTC); vital signs (VS) and laboratory
(LB) records, one per subject, test and date (VSDTC, LBDTC), with the
numeric result (VSSTRESN in kg for the test WEIGHT, LBSTRESN in
umol/L for the test CREAT); and the subject-level dataset (ADSL) with
the age in years (AGE) and the sex (SEX). An administration gives a
dose record and a sample gives a concentration record.
Variables:
ASEQ: the record's number within the subject, in the order ofADTM, a sample before a dose at the same date/time.ADTM: the date/time of the administration or of the sample.EVID: 1 for a dose record and 0 for a concentration record.WT: the subject's latest weight result dated on or before the date ofADTM; empty when there is none.CREAT: the subject's latest creatinine result dated on or before the date ofADTM; empty when there is none.CRCL: the Cockcroft-Gault creatinine clearance in mL/min, not rounded: (140 -AGE) xWTx 1.23 /CREATfor a male subject, with 1.04 in place of 1.23 for a female subject; empty whenWTorCREATis empty.
Note: a result counts from its date onward, whatever the time of day of the record, and a result dated after the record is never used. A record of the test with no result, such as a weight not measured at a visit, is passed over, so the earlier result stays in force.
Inputs
Under review5 source filesinput/adsl.csv
Edit2 rows| STUDYID | USUBJID | AGE | AGEU | SEX |
|---|---|---|---|---|
| YAMAA-01 | 54 | YEARS | M | |
| YAMAA-01 | 67 | YEARS | F |
input/ex.csv
Edit3 rows| STUDYID | USUBJID | EXSEQ | EXTRT | EXDOSE | EXDOSU | EXSTDTC |
|---|---|---|---|---|---|---|
| YAMAA-01 | 1 | DRUG X | 100 | mg | 2025-03-10T08:00 | |
| YAMAA-01 | 2 | DRUG X | 100 | mg | 2025-03-17T08:00 | |
| YAMAA-01 | 1 | DRUG X | 100 | mg | 2025-03-10T09:00 |
input/lb.csv
Edit4 rows| STUDYID | USUBJID | LBSEQ | LBTESTCD | LBSTRESN | LBSTRESU | VISIT | LBDTC |
|---|---|---|---|---|---|---|---|
| YAMAA-01 | 1 | ALT | 31 | U/L | SCREENING | 2025-03-03 | |
| YAMAA-01 | 2 | CREAT | 88 | umol/L | SCREENING | 2025-03-03 | |
| YAMAA-01 | 3 | CREAT | 97 | umol/L | WEEK 2 | 2025-03-24 | |
| YAMAA-01 | 1 | CREAT | 71 | umol/L | DAY 2 | 2025-03-11 |
input/pc.csv
Edit7 rows| STUDYID | USUBJID | PCSEQ | PCTESTCD | PCTPT | PCDTC |
|---|---|---|---|---|---|
| YAMAA-01 | 1 | DRGX | 2 h | 2025-03-10T10:00 | |
| YAMAA-01 | 2 | DRGX | Pre-dose | 2025-03-17T07:30 | |
| YAMAA-01 | 3 | DRGX | Week 2 | 2025-03-24T09:00 | |
| YAMAA-01 | 4 | DRGX | Week 4 | 2025-04-07T09:00 | |
| YAMAA-01 | 1 | DRGX | 2 h | 2025-03-10T11:00 | |
| YAMAA-01 | 2 | DRGX | 24 h | 2025-03-11T09:00 | |
| YAMAA-01 | 3 | DRGX | Week 1 | 2025-03-18T09:00 |
input/vs.csv
Edit6 rows| STUDYID | USUBJID | VSSEQ | VSTESTCD | VSSTRESN | VSSTRESU | VSSTAT | VISIT | VSDTC |
|---|---|---|---|---|---|---|---|---|
| YAMAA-01 | 1 | HEIGHT | 176 | cm | — | SCREENING | 2025-03-03 | |
| YAMAA-01 | 2 | WEIGHT | 80 | kg | — | SCREENING | 2025-03-03 | |
| YAMAA-01 | 3 | WEIGHT | 78.5 | kg | — | WEEK 1 | 2025-03-17 | |
| YAMAA-01 | 4 | WEIGHT | — | — | NOT DONE | WEEK 3 | 2025-03-31 | |
| YAMAA-01 | 1 | WEIGHT | 61.2 | kg | — | SCREENING | 2025-03-04 | |
| YAMAA-01 | 2 | WEIGHT | 60.4 | kg | — | WEEK 1 | 2025-03-18 |
Expected output
Under review10 expected rowsexpected/adppk.csv
Edit10 rows| STUDYID | USUBJID | ASEQ | ADTM | EVID | WT | CREAT | CRCL |
|---|---|---|---|---|---|---|---|
| YAMAA-01 | 1 | 2025-03-10T08:00:00 | 1 | 80 | 88 | 96.16363636363636 | |
| YAMAA-01 | 2 | 2025-03-10T10:00:00 | 0 | 80 | 88 | 96.16363636363636 | |
| YAMAA-01 | 3 | 2025-03-17T07:30:00 | 0 | 78.5 | 88 | 94.36056818181818 | |
| YAMAA-01 | 4 | 2025-03-17T08:00:00 | 1 | 78.5 | 88 | 94.36056818181818 | |
| YAMAA-01 | 5 | 2025-03-24T09:00:00 | 0 | 78.5 | 97 | 85.60546391752577 | |
| YAMAA-01 | 6 | 2025-04-07T09:00:00 | 0 | 78.5 | 97 | 85.60546391752577 | |
| YAMAA-01 | 1 | 2025-03-10T09:00:00 | 1 | 61.2 | — | — | |
| YAMAA-01 | 2 | 2025-03-10T11:00:00 | 0 | 61.2 | — | — | |
| YAMAA-01 | 3 | 2025-03-11T09:00:00 | 0 | 61.2 | 71 | 65.4409014084507 | |
| YAMAA-01 | 4 | 2025-03-18T09:00:00 | 0 | 60.4 | 71 | 64.5854647887324 |
Human review and assessment
| Dataset Name | Variable Name | Variable Label | Type | Codelist/Controlled Terms | Core | Computational Method | Origin |
|---|---|---|---|---|---|---|---|
| ADPPK | STUDYID | Study Identifier | character | Set per constructed row; see the Row construction sheet. | Derived | ||
| ADPPK | USUBJID | Unique Subject Identifier | character | Set per constructed row; see the Row construction sheet. | Derived | ||
| ADPPK | ADTM | Analysis Date/Time | numeric | ISO 8601 | Set per constructed row; see the Row construction sheet. | Derived | |
| ADPPK | EVID | Event ID | numeric | 0, 1 | Set per constructed row; see the Row construction sheet. | Derived | |
| ADPPK | WT | Body Weight (kg) | numeric | Take VSSTRESN from the last VS record whose STUDYID equals STUDYID and USUBJID equals USUBJID, where ADT is VSDTC or more, and a record with no VSDTC never matches, where VS.VSTESTCD = 'WEIGHT' AND VS.VSSTRESN IS NOT NULL, ordered by VS.VSDTC then VS.VSSEQ, and no match yields blank. | Derived | ||
| ADPPK | CREAT | Serum Creatinine (umol/L) | numeric | Take LBSTRESN from the last LB record whose STUDYID equals STUDYID and USUBJID equals USUBJID, where ADT is LBDTC or more, and a record with no LBDTC never matches, where LB.LBTESTCD = 'CREAT' AND LB.LBSTRESN IS NOT NULL, ordered by LB.LBDTC then LB.LBSEQ, and no match yields blank. | Derived | ||
| ADPPK | CRCL | Creatinine Clearance (mL/min) | numeric | If SEX = 'M' then compute (140 - AGE) * WT * 1.23 / CREAT; If SEX = 'F' then compute (140 - AGE) * WT * 1.04 / CREAT; otherwise blank. | Derived | ||
| ADPPK | ASEQ | Analysis Sequence Number | numeric | Row number within each group of STUDYID, USUBJID, ordered by ADTM then EVID. | Derived |
| Template | Include when | STUDYID | USUBJID | ADTM | EVID |
|---|---|---|---|---|---|
| dose | Copy EX.STUDYID | Copy EX.USUBJID | Copy EX.EXSTDTC | Constant "1" | |
| concentration | Copy PC.STUDYID | Copy PC.USUBJID | Copy PC.PCDTC | Constant "0" |
| Variable | Permitted values |
|---|---|
| EVID | 0, 1 |
| Version | Date | Author | Description | Reviewer | Sign-off |
|---|---|---|---|---|---|
| 1.8 | 2026-11-19 | yamaa docs build | State open and closed range endpoints, including bounds of zero | ||
| 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-adppk-time-varying-covariates/full.md
Edit32 linesFollowing CDISC ADaM standards, use the provided ADSL, EX, LB, PC, and VS datasets to create an ADPPK dataset with one record per administration in EX and per sample in PC.
The output dataset should contain the following columns in this order: STUDYID, USUBJID, ASEQ, ADTM, EVID, WT, CREAT, CRCL
- An EX administration gives a dose record: EVID is 1 and ADTM is the date/time of the administration (EXSTDTC).
- A PC sample gives a concentration record: EVID is 0 and ADTM is the date/time of the sample (PCDTC).
- ADTM is written as YYYY-MM-DDThh:mm:ss, with the seconds always shown.
- ASEQ is the record's number within the subject, from 1, in the order of ADTM, a sample before a dose at the same date/time.
- WT is the subject's latest weight result (VSSTRESN of the VS test "WEIGHT", in kg) dated on or before the date of ADTM.
- CREAT is the subject's latest creatinine result (LBSTRESN of the LB test "CREAT", in umol/L) dated on or before the date of ADTM.
- A result counts from its date onward, whatever the time of day of the record, and a result dated after the record is never used.
- A record of the test with no result, such as a weight not measured at a visit, is passed over, so the earlier result stays in force.
- WT or CREAT has no value when the subject has no result dated on or before the date of ADTM.
- CRCL is the Cockcroft-Gault creatinine clearance in mL/min, not rounded: (140 - AGE) x WT x 1.23 / CREAT for a male subject (SEX "M"), with 1.04 in place of 1.23 for a female subject (SEX "F"), AGE and SEX being the subject's ADSL values.
- CRCL has no value when WT or CREAT has no value.
Read the source datasets from /app/input and save the completed dataset as /app/output/adppk.csv.
prompts/adam-adppk-time-varying-covariates/conventions.md
Edit13 linesFollowing CDISC ADaM standards, use the provided ADSL, EX, LB, PC, and VS datasets to create an ADPPK dataset with one record per administration in EX and per sample in PC.
The output dataset should contain the following columns in this order: STUDYID, USUBJID, ASEQ, ADTM, EVID, WT, CREAT, CRCL
- EVID is 1 for a dose record and 0 for a concentration record.
- ADTM is written as YYYY-MM-DDThh:mm:ss, with the seconds always shown.
- CRCL is the Cockcroft-Gault creatinine clearance, not rounded.
Read the source datasets from /app/input and save the completed dataset as /app/output/adppk.csv.
prompts/adam-adppk-time-varying-covariates/brief.md
Edit9 linesFollowing CDISC ADaM standards, use the provided ADSL, EX, LB, PC, and VS datasets to create an ADPPK dataset with one record per administration in EX and per sample in PC.
The output dataset should contain the following columns in this order: STUDYID, USUBJID, ASEQ, ADTM, EVID, WT, CREAT, CRCL
Read the source datasets from /app/input and save the completed dataset as /app/output/adppk.csv.
R
Edit3 lineslibrary(yamaa)yamaa_spec("spec.yaml")$run()$outputPython
Edit3 linesimport yamaayamaa.spec("spec.yaml").run().outputsolutions/adam-adppk-time-varying-covariates/result.R
Edit70 lines# Reference solution for the yamaa benchmark adam-adppk-time-varying-covariates (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.suppressPackageStartupMessages({ library(dplyr) library(readr)})read_src <- function(name) { read_csv(file.path("/app/input", paste0(name, ".csv")), col_types = cols(.default = col_character()), na = "")}adsl <- read_src("adsl")ex <- read_src("ex")lb <- read_src("lb")pc <- read_src("pc")vs <- read_src("vs")full_dtm <- function(x) { x <- ifelse(nchar(x) == 10, paste0(x, "T00:00"), x) ifelse(nchar(x) == 16, paste0(x, ":00"), x)}events <- bind_rows( ex %>% transmute(STUDYID, USUBJID, ADTM = full_dtm(EXSTDTC), EVID = 1L, SRCSEQ = as.numeric(EXSEQ)), pc %>% transmute(STUDYID, USUBJID, ADTM = full_dtm(PCDTC), EVID = 0L, SRCSEQ = as.numeric(PCSEQ))) %>% filter(!is.na(ADTM)) %>% arrange(USUBJID, ADTM, EVID, SRCSEQ) %>% group_by(USUBJID) %>% mutate(ASEQ = row_number()) %>% ungroup() %>% mutate(ADT = substr(ADTM, 1, 10))weights <- vs %>% filter(VSTESTCD == "WEIGHT") %>% transmute(USUBJID, DT = substr(VSDTC, 1, 10), DTC = VSDTC, SEQ = as.numeric(VSSEQ), VAL = as.numeric(VSSTRESN)) %>% filter(!is.na(VAL), !is.na(DT))creats <- lb %>% filter(LBTESTCD == "CREAT") %>% transmute(USUBJID, DT = substr(LBDTC, 1, 10), DTC = LBDTC, SEQ = as.numeric(LBSEQ), VAL = as.numeric(LBSTRESN)) %>% filter(!is.na(VAL), !is.na(DT))latest <- function(results, usubjid, adt) { vapply(seq_along(usubjid), function(i) { r <- results %>% filter(USUBJID == usubjid[i], DT <= adt[i]) %>% arrange(DT, DTC, SEQ) if (nrow(r) == 0) NA_real_ else r$VAL[nrow(r)] }, numeric(1))}adppk <- events %>% mutate(WT = latest(weights, USUBJID, ADT), CREAT = latest(creats, USUBJID, ADT)) %>% left_join(adsl %>% transmute(USUBJID, AGE = as.numeric(AGE), SEX), by = "USUBJID") %>% mutate(FACTOR = case_when(SEX == "M" ~ 1.23, SEX == "F" ~ 1.04, TRUE ~ NA_real_), CRCL = (140 - AGE) * WT * FACTOR / CREAT) %>% select(STUDYID, USUBJID, ASEQ, ADTM, EVID, WT, CREAT, CRCL)write_csv(adppk, file.path("/app/output", "adppk.csv"), na = "")solutions/adam-adppk-time-varying-covariates/result.py
Edit108 lines# Reference solution for the yamaa benchmark adam-adppk-time-varying-covariates (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 pandas as pdIN = "/app/input"OUT = "/app/output/adppk.csv"def read(name): return pd.read_csv(f"{IN}/{name}.csv", dtype=str, keep_default_na=False)def adtm(value): value = value.strip() date, _, time = value.partition("T") parts = [p for p in time.split(":") if p != ""] if time else [] parts = (parts + ["00", "00", "00"])[:3] parts[2] = parts[2].split(".")[0].zfill(2) return f"{date}T{parts[0].zfill(2)}:{parts[1].zfill(2)}:{parts[2]}"def results(frame, testcd_col, testcd, value_col, date_col, seq_col): rows = frame[frame[testcd_col].str.strip() == testcd].copy() rows["value"] = pd.to_numeric(rows[value_col].str.strip(), errors="coerce") rows = rows[rows["value"].notna()] rows["date"] = rows[date_col].str.strip().str[:10] rows = rows[rows["date"].str.len() == 10] rows["seq"] = pd.to_numeric(rows[seq_col], errors="coerce") rows = rows.sort_values(["USUBJID", "date", "seq"], kind="stable") return {k: list(zip(g["date"], g["value"])) for k, g in rows.groupby("USUBJID")}def latest(history, subject, date): found = None for d, v in history.get(subject, []): if d <= date: found = v return founddef text(value): if value is None: return "" if float(value).is_integer(): return str(int(value)) return repr(float(value))adsl = read("adsl")ex = read("ex")pc = read("pc")vs = read("vs")lb = read("lb")weights = results(vs, "VSTESTCD", "WEIGHT", "VSSTRESN", "VSDTC", "VSSEQ")creats = results(lb, "LBTESTCD", "CREAT", "LBSTRESN", "LBDTC", "LBSEQ")subjects = { r.USUBJID: (pd.to_numeric(r.AGE, errors="coerce"), r.SEX.strip()) for r in adsl.itertuples()}doses = pd.DataFrame({ "STUDYID": ex["STUDYID"], "USUBJID": ex["USUBJID"], "ADTM": ex["EXSTDTC"].map(adtm), "EVID": 1, "SRCSEQ": pd.to_numeric(ex["EXSEQ"], errors="coerce"),})samples = pd.DataFrame({ "STUDYID": pc["STUDYID"], "USUBJID": pc["USUBJID"], "ADTM": pc["PCDTC"].map(adtm), "EVID": 0, "SRCSEQ": pd.to_numeric(pc["PCSEQ"], errors="coerce"),})adppk = pd.concat([doses, samples], ignore_index=True)adppk = adppk.sort_values( ["STUDYID", "USUBJID", "ADTM", "EVID", "SRCSEQ"], kind="stable").reset_index(drop=True)adppk["ASEQ"] = adppk.groupby("USUBJID").cumcount() + 1wt, creat, crcl = [], [], []for r in adppk.itertuples(): date = r.ADTM[:10] w = latest(weights, r.USUBJID, date) c = latest(creats, r.USUBJID, date) age, sex = subjects.get(r.USUBJID, (None, "")) factor = {"M": 1.23, "F": 1.04}.get(sex) if w is None or c is None or factor is None or age is None or pd.isna(age): cl = None else: cl = (140 - age) * w * factor / c wt.append(text(w)) creat.append(text(c)) crcl.append(text(cl))adppk["WT"] = wtadppk["CREAT"] = creatadppk["CRCL"] = crcladppk[["STUDYID", "USUBJID", "ASEQ", "ADTM", "EVID", "WT", "CREAT", "CRCL"]].to_csv( OUT, index=False, lineterminator="\n")solutions/adam-adppk-time-varying-covariates/result.sas
Edit153 lines/* opensas reference solution for the yamaa benchmark adam-adppk-time-varying-covariates. Reads the benchmark inputs and derives the requested output. Execute with the existing opensas runtime: opensas /app/output/result.sas. */options missing=' ';data adsl; infile '/app/input/adsl.csv' dsd dlm=',' firstobs=2 truncover; length STUDYID $20 USUBJID $40 AGE 8 AGEU $10 SEX $1; input STUDYID $ USUBJID $ AGE AGEU $ SEX $; SEX = compress(SEX, "0D"x);run;data ex; infile '/app/input/ex.csv' dsd dlm=',' firstobs=2 truncover; length STUDYID $20 USUBJID $40 EXSEQ 8 EXTRT $40 EXDOSE 8 EXDOSU $10 EXSTDTC $19; input STUDYID $ USUBJID $ EXSEQ EXTRT $ EXDOSE EXDOSU $ EXSTDTC $; EXSTDTC = compress(EXSTDTC, "0D"x);run;data pc; infile '/app/input/pc.csv' dsd dlm=',' firstobs=2 truncover; length STUDYID $20 USUBJID $40 PCSEQ 8 PCTESTCD $8 PCTPT $40 PCDTC $19; input STUDYID $ USUBJID $ PCSEQ PCTESTCD $ PCTPT $ PCDTC $; PCDTC = compress(PCDTC, "0D"x);run;data vs; infile '/app/input/vs.csv' dsd dlm=',' firstobs=2 truncover; length STUDYID $20 USUBJID $40 VSSEQ 8 VSTESTCD $8 VSSTRESN 8 VSSTRESU $10 VSSTAT $10 VISIT $40 VSDTC $19; input STUDYID $ USUBJID $ VSSEQ VSTESTCD $ VSSTRESN VSSTRESU $ VSSTAT $ VISIT $ VSDTC $; VSDTC = compress(VSDTC, "0D"x);run;data lb; infile '/app/input/lb.csv' dsd dlm=',' firstobs=2 truncover; length STUDYID $20 USUBJID $40 LBSEQ 8 LBTESTCD $8 LBSTRESN 8 LBSTRESU $10 VISIT $40 LBDTC $19; input STUDYID $ USUBJID $ LBSEQ LBTESTCD $ LBSTRESN LBSTRESU $ VISIT $ LBDTC $; LBDTC = compress(LBDTC, "0D"x);run;/* one record per administration and per sample */data events; length STUDYID $20 USUBJID $40 ADTM $19 ADT $10 EVID 8 SRCSEQ 8 DTC $19; keep STUDYID USUBJID ADTM ADT EVID SRCSEQ; set ex(in=inex) pc(in=inpc); if inex then do; EVID = 1; DTC = strip(EXSTDTC); SRCSEQ = EXSEQ; end; else do; EVID = 0; DTC = strip(PCDTC); SRCSEQ = PCSEQ; end; if length(DTC) = 10 then ADTM = cats(DTC, 'T00:00:00'); else if length(DTC) = 13 then ADTM = cats(DTC, ':00:00'); else if length(DTC) = 16 then ADTM = cats(DTC, ':00'); else ADTM = DTC; ADT = substr(ADTM, 1, 10);run;proc sort data=events; by STUDYID USUBJID ADTM EVID SRCSEQ;run;data events; set events; by STUDYID USUBJID; if first.USUBJID then ASEQ = 0; ASEQ + 1;run;/* covariate results that carry a value */data wt; set vs; where VSTESTCD = 'WEIGHT' and VSSTRESN is not missing; length CDT $10; CDT = substr(VSDTC, 1, 10); keep STUDYID USUBJID CDT VSDTC VSSEQ VSSTRESN;run;data creat; set lb; where LBTESTCD = 'CREAT' and LBSTRESN is not missing; length CDT $10; CDT = substr(LBDTC, 1, 10); keep STUDYID USUBJID CDT LBDTC LBSEQ LBSTRESN;run;proc sql; create table ewt as select e.STUDYID, e.USUBJID, e.ASEQ, w.VSDTC, w.VSSEQ, w.VSSTRESN from events as e left join wt as w on e.STUDYID = w.STUDYID and e.USUBJID = w.USUBJID and w.CDT <= e.ADT order by e.STUDYID, e.USUBJID, e.ASEQ, w.VSDTC, w.VSSEQ; create table ecr as select e.STUDYID, e.USUBJID, e.ASEQ, c.LBDTC, c.LBSEQ, c.LBSTRESN from events as e left join creat as c on e.STUDYID = c.STUDYID and e.USUBJID = c.USUBJID and c.CDT <= e.ADT order by e.STUDYID, e.USUBJID, e.ASEQ, c.LBDTC, c.LBSEQ;quit;data ewt; set ewt; by STUDYID USUBJID ASEQ; if last.ASEQ; WT = VSSTRESN; keep STUDYID USUBJID ASEQ WT;run;data ecr; set ecr; by STUDYID USUBJID ASEQ; if last.ASEQ; CREAT = LBSTRESN; keep STUDYID USUBJID ASEQ CREAT;run;proc sort data=adsl out=adsl_s(keep=STUDYID USUBJID AGE SEX); by STUDYID USUBJID;run;data adppk0; merge events(in=ine) ewt ecr; by STUDYID USUBJID ASEQ; if ine;run;data adppk; retain STUDYID USUBJID ASEQ ADTM EVID WT CREAT CRCL; merge adppk0(in=ine) adsl_s; by STUDYID USUBJID; if ine; CRCL = .; if not missing(WT) and not missing(CREAT) and not missing(AGE) then do; if SEX = 'M' then CRCL = (140 - AGE) * WT * 1.23 / CREAT; else if SEX = 'F' then CRCL = (140 - AGE) * WT * 1.04 / CREAT; end; keep STUDYID USUBJID ASEQ ADTM EVID WT CREAT CRCL;run;proc sort data=adppk; by STUDYID USUBJID ASEQ;run;/* CSV written with full numeric precision; a missing value is an empty field */data _null_; set adppk; file '/app/output/adppk.csv'; length line $400 cwt ccreat ccrcl $40; if _n_ = 1 then put 'STUDYID,USUBJID,ASEQ,ADTM,EVID,WT,CREAT,CRCL'; if missing(WT) then cwt = ''; else cwt = strip(put(WT, best32.)); if missing(CREAT) then ccreat = ''; else ccreat = strip(put(CREAT, best32.)); if missing(CRCL) then ccrcl = ''; else ccrcl = strip(put(CRCL, best32.)); line = catx(',', STUDYID, USUBJID, strip(put(ASEQ, best32.)), ADTM, strip(put(EVID, best32.))); line = strip(line) || ',' || strip(cwt) || ',' || strip(ccreat) || ',' || strip(ccrcl); put line;run;
yamaa