Review ask

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

Lifecycle: draftEditUnder review
What this benchmark means
README.md

Public entries: Python and R. Passing coverage requires an installed inventory.

Goal: repeat on every dose record and every pharmacokinetic (PK) concentration record of a population PK dataset the subject's baseline covariates: age, sex and race with numeric codes (SEXN, RACEN), weight and height with the body mass index and the body surface area (WTBL, HTBL, BMIBL, BSABL), the baseline creatinine, alanine aminotransferase and bilirubin (CREATBL, ALTBL, TBILBL), and the creatinine clearance and estimated glomerular filtration rate (CRCLBL, EGFRBL).

Input: exposure (EX) records, one per administration, with the date/time (EXSTDTC), and PK concentration (PC) records with the collection date/time (PCDTC); an administration gives a dose record and a sample gives a concentration record. The subject-level dataset (ADSL) has AGE in years, SEX and RACE. Vital signs (VS) hold the tests WEIGHT (kg) and HEIGHT (cm), and laboratory (LB) records hold the tests CREAT (umol/L), ALT (U/L) and BILI (umol/L) among others, with the numeric result in VSSTRESN or LBSTRESN. A subject's baseline record of a test is the one flagged Y in VSBLFL or LBBLFL.

Variables:

  • ASEQ: the record's number within the subject, in the order of ADTM.
  • ADTM: the date/time of the administration or of the sample.
  • EVID: 1 for a dose record and 0 for a concentration record.
  • AGE, SEX, RACE: as in ADSL.
  • SEXN: 1 for M and 2 for F.
  • RACEN: 1 for AMERICAN INDIAN OR ALASKA NATIVE, 2 for ASIAN, 3 for BLACK OR AFRICAN AMERICAN, 4 for NATIVE HAWAIIAN OR OTHER PACIFIC ISLANDER, 5 for WHITE and 6 for any other value.
  • WTBL, HTBL: the baseline weight and height; empty when the subject has no baseline record of the test.
  • BMIBL: WTBL divided by the square of HTBL in metres (HTBL / 100).
  • BSABL: the Mosteller body surface area, the square root of HTBL x WTBL / 3600.
  • CREATBL, ALTBL, TBILBL: the baseline results of CREAT, ALT and BILI; empty when the subject has no baseline record of the test.
  • CRCLBL: the Cockcroft-Gault creatinine clearance in mL/min: (140 - AGE) x WTBL x 1.23 / CREATBL for a male subject, with 1.04 in place of 1.23 for a female subject.
  • EGFRBL: the CKD-EPI 2021 estimated glomerular filtration rate in mL/min/1.73 m2. With r = CREATBL / 88.42 / 0.9 for a male subject and CREATBL / 88.42 / 0.7 for a female subject, it is 142 x r^a x 0.9938^AGE, times 1.012 for a female subject, where the exponent a is -1.2 when r is above 1 and otherwise -0.302 for a male and -0.241 for a female subject.

Note: no computed value is rounded, and a computed value is empty when a value it is computed from is empty. Results that are not flagged as baseline, and tests other than those named, are not used.

Inputs

Under review
5 source files

input/adsl.csv

Edit
5 rows
input/adsl.csv
STUDYIDUSUBJIDAGEAGEUSEXRACE
YAMAA-0161YEARSMWHITE
YAMAA-0148YEARSFASIAN
YAMAA-0135YEARSMBLACK OR AFRICAN AMERICAN
YAMAA-0172YEARSFWHITE
YAMAA-0156YEARSFMULTIPLE

input/ex.csv

Edit
5 rows
input/ex.csv
STUDYIDUSUBJIDEXSEQEXTRTEXDOSEEXDOSUEXSTDTC
YAMAA-011DRUG X100mg2025-03-10T08:00
YAMAA-011DRUG X100mg2025-03-10T08:30
YAMAA-011DRUG X100mg2025-03-11T08:00
YAMAA-011DRUG X100mg2025-03-11T09:00
YAMAA-011DRUG X100mg2025-03-12T08:15

input/lb.csv

Edit
15 rows
input/lb.csv
STUDYIDUSUBJIDLBSEQLBTESTCDLBSTRESNLBSTRESULBBLFLVISITLBDTC
YAMAA-011ALT28U/LYSCREENING2025-03-03
YAMAA-012BILI11umol/LYSCREENING2025-03-03
YAMAA-013CREAT80umol/LYSCREENING2025-03-03
YAMAA-014GLUC5.4mmol/LYSCREENING2025-03-03
YAMAA-011ALT19U/LYSCREENING2025-03-04
YAMAA-012BILI8umol/LYSCREENING2025-03-04
YAMAA-013CREAT55umol/LYSCREENING2025-03-04
YAMAA-011ALT44U/LYSCREENING2025-03-04
YAMAA-012CREAT70umol/LYSCREENING2025-03-04
YAMAA-011ALT23U/LYSCREENING2025-03-05
YAMAA-012BILI14umol/LYSCREENING2025-03-05
YAMAA-013CREAT68umol/L—WEEK 22025-03-25
YAMAA-011ALT31U/LYSCREENING2025-03-06
YAMAA-012BILI9umol/LYSCREENING2025-03-06
YAMAA-013CREAT97umol/LYSCREENING2025-03-06

input/pc.csv

Edit
5 rows
input/pc.csv
STUDYIDUSUBJIDPCSEQPCTESTCDPCTPTPCDTC
YAMAA-011DRGX2 h2025-03-10T10:00
YAMAA-011DRGX2 h2025-03-10T10:30
YAMAA-011DRGX2 h2025-03-11T10:00
YAMAA-011DRGX2 h2025-03-11T11:00
YAMAA-011DRGX2 h2025-03-12T10:15

input/vs.csv

Edit
11 rows
input/vs.csv
STUDYIDUSUBJIDVSSEQVSTESTCDVSSTRESNVSSTRESUVSBLFLVISITVSDTC
YAMAA-011HEIGHT178cmYSCREENING2025-03-03
YAMAA-012WEIGHT85kg—SCREENING2025-03-03
YAMAA-013WEIGHT84.5kgYDAY 12025-03-10
YAMAA-014WEIGHT83.9kg—WEEK 22025-03-24
YAMAA-011HEIGHT162cmYSCREENING2025-03-04
YAMAA-012WEIGHT58kgYDAY 12025-03-10
YAMAA-011WEIGHT91.3kgYDAY 12025-03-11
YAMAA-011HEIGHT155.5cmYSCREENING2025-03-05
YAMAA-012WEIGHT49.8kgYDAY 12025-03-11
YAMAA-011HEIGHT168cmYSCREENING2025-03-06
YAMAA-012WEIGHT70.2kgYDAY 12025-03-12

Expected output

Under review
10 expected rows

expected/adppk.csv

Edit
10 rows
expected/adppk.csv
STUDYIDUSUBJIDASEQADTMEVIDAGESEXSEXNRACERACENWTBLHTBLBMIBLBSABLCREATBLALTBLTBILBLCRCLBLEGFRBL
YAMAA-0112025-03-10T08:00:00161M1WHITE584.517826.6696124226739042.044029245278931802811102.635812596.5540557410661
YAMAA-0122025-03-10T10:00:00061M1WHITE584.517826.6696124226739042.044029245278931802811102.635812596.5540557410661
YAMAA-0112025-03-10T08:30:00148F2ASIAN25816222.100289590001521.615549442140351155198100.8989090909091109.69337151096254
YAMAA-0122025-03-10T10:30:00048F2ASIAN25816222.100289590001521.615549442140351155198100.8989090909091109.69337151096254
YAMAA-0112025-03-11T08:00:00135M1BLACK OR AFRICAN AMERICAN391.3———7044—168.4485118.73341597121299
YAMAA-0122025-03-11T10:00:00035M1BLACK OR AFRICAN AMERICAN391.3———7044—168.4485118.73341597121299
YAMAA-0112025-03-11T09:00:00172F2WHITE549.8155.520.595320561201811.4666571969391256—2314——
YAMAA-0122025-03-11T11:00:00072F2WHITE549.8155.520.595320561201811.4666571969391256—2314——
YAMAA-0112025-03-12T08:15:00156F2MULTIPLE670.216824.872448979591841.80997237547980279731963.2234226804123859.164964926871065
YAMAA-0122025-03-12T10:15:00056F2MULTIPLE670.216824.872448979591841.80997237547980279731963.2234226804123859.164964926871065
Shaded columns are derived— = missing value

Human review and assessment

Your review

3 questions and your comments · View benchmark discussions

Mapping spec

Generated from the benchmark YAML; do not edit by hand

Dataset NameVariable NameVariable LabelTypeCodelist/Controlled TermsCoreComputational MethodOrigin
ADPPKSTUDYIDStudy IdentifiercharacterSet per constructed row; see the Row construction sheet.Derived
ADPPKUSUBJIDUnique Subject IdentifiercharacterSet per constructed row; see the Row construction sheet.Derived
ADPPKADTMAnalysis Date/TimenumericISO 8601Set per constructed row; see the Row construction sheet.Derived
ADPPKEVIDEvent IDnumeric0, 1Set per constructed row; see the Row construction sheet.Derived
ADPPKAGEAgenumericCopy value from ADSL.AGE.Predecessor
ADPPKSEXSexcharacterCopy value from ADSL.SEX.Predecessor
ADPPKSEXNSex (N)numericRecode SEX: "M" → "1", "F" → "2"; missing values stay missing; unlisted values are errors.Derived
ADPPKRACERacecharacterCopy value from ADSL.RACE.Predecessor
ADPPKRACENRace (N)numericIf RACE = 'AMERICAN INDIAN OR ALASKA NATIVE' then "1"; If RACE = 'ASIAN' then "2"; If RACE = 'BLACK OR AFRICAN AMERICAN' then "3"; If RACE = 'NATIVE HAWAIIAN OR OTHER PACIFIC ISLANDER' then "4"; If RACE = 'WHITE' then "5"; otherwise "6".Derived
ADPPKWTBLBaseline Weight (kg)numericTake WEIGHT from the VS record whose STUDYID equals STUDYID and USUBJID equals USUBJID, where VS.VSBLFL = 'Y' AND VS.VSTESTCD IN ('WEIGHT', 'HEIGHT'), and no match yields blank.Derived
ADPPKHTBLBaseline Height (cm)numericTake HEIGHT from the VS record whose STUDYID equals STUDYID and USUBJID equals USUBJID, where VS.VSBLFL = 'Y' AND VS.VSTESTCD IN ('WEIGHT', 'HEIGHT'), and no match yields blank.Derived
ADPPKBMIBLBaseline Body Mass Index (kg/m2)numericCompute WTBL / POWER(HTBL / 100, 2).Derived
ADPPKBSABLBaseline Body Surface Area (m2)numericCompute SQRT(HTBL * WTBL / 3600).Derived
ADPPKCREATBLBaseline Creatinine (umol/L)numericTake CREAT from the LB record whose STUDYID equals STUDYID and USUBJID equals USUBJID, where LB.LBBLFL = 'Y' AND LB.LBTESTCD IN ('CREAT', 'ALT', 'BILI'), and no match yields blank.Derived
ADPPKALTBLBaseline Alanine Aminotransferase (U/L)numericTake ALT from the LB record whose STUDYID equals STUDYID and USUBJID equals USUBJID, where LB.LBBLFL = 'Y' AND LB.LBTESTCD IN ('CREAT', 'ALT', 'BILI'), and no match yields blank.Derived
ADPPKTBILBLBaseline Bilirubin (umol/L)numericTake BILI from the LB record whose STUDYID equals STUDYID and USUBJID equals USUBJID, where LB.LBBLFL = 'Y' AND LB.LBTESTCD IN ('CREAT', 'ALT', 'BILI'), and no match yields blank.Derived
ADPPKCRCLBLBaseline Creatinine Clearance (mL/min)numericIf SEX = 'M' then compute (140 - AGE) * WTBL * 1.23 / CREATBL; If SEX = 'F' then compute (140 - AGE) * WTBL * 1.04 / CREATBL; otherwise blank.Derived
ADPPKEGFRBLBaseline Estimated GFR (mL/min/1.73 m2)numericIf SEX = 'M' AND CREATR > 1 then compute 142 * POWER(CREATR, -1.2) * POWER(0.9938, AGE); If SEX = 'M' then compute 142 * POWER(CREATR, -0.302) * POWER(0.9938, AGE); If SEX = 'F' AND CREATR > 1 then compute 142 * POWER(CREATR, -1.2) * POWER(0.9938, AGE) * 1.012; If SEX = 'F' then compute 142 * POWER(CREATR, -0.241) * POWER(0.9938, AGE) * 1.012; otherwise blank.Derived
ADPPKASEQAnalysis Sequence NumbernumericRow number within each group of STUDYID, USUBJID, ordered by ADTM then EVID.Derived
TemplateInclude whenSTUDYIDUSUBJIDADTMEVID
doseCopy EX.STUDYIDCopy EX.USUBJIDCopy EX.EXSTDTCConstant "1"
concentrationCopy PC.STUDYIDCopy PC.USUBJIDCopy PC.PCDTCConstant "0"
VariablePermitted values
EVID0, 1
VersionDateAuthorDescriptionReviewerSign-off
1.82026-11-19yamaa docs buildState open and closed range endpoints, including bounds of zero
1.72026-10-20yamaa docs buildRead 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.62026-10-17yamaa docs buildDescribe collected date parts written as ISO 8601 date text and times of day counted in seconds since midnight
1.52026-10-17yamaa docs buildName 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.42026-10-15yamaa docs buildState datetime precision codes through the hour and minute, and complete only the time parts a collected datetime lacks
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/adam-adppk-baseline-covariates/full.md

Edit
40 lines

Following CDISC ADaM standards, use the provided ADSL, EX, LB, PC, and VS datasets to create an ADPPK dataset with one record per subject per administration or pharmacokinetic sample.

The output dataset should contain the following columns in this order: STUDYID, USUBJID, ASEQ, ADTM, EVID, AGE, SEX, SEXN, RACE, RACEN, WTBL, HTBL, BMIBL, BSABL, CREATBL, ALTBL, TBILBL, CRCLBL, EGFRBL

Each EX record gives a dose record and each PC record a concentration record. Every record holds its subject's baseline covariates.

  • ADTM is the date/time of the administration (EXSTDTC) or of the sample (PCDTC), in the form YYYY-MM-DDThh:mm:ss with the seconds shown.
  • ASEQ numbers the subject's records from 1 in the order of ADTM.
  • EVID is 1 for a dose record and 0 for a concentration record.
  • AGE, SEX and RACE are as in ADSL. SEXN is 1 for "M" and 2 for "F". RACEN is 2 for "ASIAN", 3 for "BLACK OR AFRICAN AMERICAN", 5 for "WHITE" and 6 for any other value.
  • WTBL and HTBL are the baseline results (VSSTRESN) of the VS tests "WEIGHT" and "HEIGHT", and CREATBL, ALTBL and TBILBL the baseline results (LBSTRESN) of the LB tests "CREAT", "ALT" and "BILI". The baseline record of a test is the one flagged "Y" in VSBLFL or LBBLFL, and each of these has no value when the subject has none. Results that are not flagged as baseline, and tests other than those named, are not used.
  • BMIBL is WTBL divided by the square of HTBL in metres (HTBL / 100), and BSABL is the Mosteller body surface area, the square root of HTBL x WTBL / 3600.
  • CRCLBL is the Cockcroft-Gault creatinine clearance in mL/min: (140 - AGE) x WTBL x 1.23 / CREATBL for a male subject, with 1.04 in place of 1.23 for a female subject.
  • EGFRBL is the CKD-EPI 2021 estimated glomerular filtration rate in mL/min/1.73 m2. With r = CREATBL / 88.42 / 0.9 for a male subject and CREATBL / 88.42 / 0.7 for a female subject, it is 142 x r^a x 0.9938^AGE, times 1.012 for a female subject, where the exponent a is -1.2 when r is above 1 and otherwise -0.302 for a male and -0.241 for a female subject.
  • BMIBL, BSABL, CRCLBL and EGFRBL are not rounded, and each has no value when a value it is computed from has no value.

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

prompts/adam-adppk-baseline-covariates/conventions.md

Edit
17 lines

Following CDISC ADaM standards, use the provided ADSL, EX, LB, PC, and VS datasets to create an ADPPK dataset with one record per subject per administration or pharmacokinetic sample.

The output dataset should contain the following columns in this order: STUDYID, USUBJID, ASEQ, ADTM, EVID, AGE, SEX, SEXN, RACE, RACEN, WTBL, HTBL, BMIBL, BSABL, CREATBL, ALTBL, TBILBL, CRCLBL, EGFRBL

ADTM is in the form YYYY-MM-DDThh:mm:ss with the seconds shown. EVID is 1 for a dose record and 0 for a concentration record. SEXN is 1 for "M" and 2 for "F". RACEN is 2 for "ASIAN", 3 for "BLACK OR AFRICAN AMERICAN", 5 for "WHITE", or 6. BSABL is the Mosteller body surface area, CRCLBL the Cockcroft-Gault creatinine clearance, and EGFRBL the CKD-EPI 2021 estimated glomerular filtration rate. BMIBL, BSABL, CRCLBL and EGFRBL are not rounded.

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

prompts/adam-adppk-baseline-covariates/brief.md

Edit
10 lines

Following CDISC ADaM standards, use the provided ADSL, EX, LB, PC, and VS datasets to create an ADPPK dataset with one record per subject per administration or pharmacokinetic sample.

The output dataset should contain the following columns in this order: STUDYID, USUBJID, ASEQ, ADTM, EVID, AGE, SEX, SEXN, RACE, RACEN, WTBL, HTBL, BMIBL, BSABL, CREATBL, ALTBL, TBILBL, CRCLBL, EGFRBL

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

yamaa code

Public calls generated from benchmark.yaml; results must match the expected output

R

Edit
3 lines
library(yamaa)yamaa_spec("spec.yaml")$run()$output

Python

Edit
3 lines
import yamaayamaa.spec("spec.yaml").run().output

Solution without yamaa

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

solutions/adam-adppk-baseline-covariates/result.R

Edit
115 lines
# Reference solution for the yamaa benchmark adam-adppk-baseline-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(tidyr)  library(readr)  library(stringr)})read_src <- function(name) {  read_csv(    file.path("/app/input", name),    col_types = cols(.default = col_character()),    na = c("", "NA"),    trim_ws = TRUE,    progress = FALSE  )}adsl <- read_src("adsl.csv")ex <- read_src("ex.csv")lb <- read_src("lb.csv")pc <- read_src("pc.csv")vs <- read_src("vs.csv")with_seconds <- function(x) {  date_part <- "[0-9]{4}-[0-9]{2}-[0-9]{2}"  case_when(    is.na(x) ~ NA_character_,    str_detect(x, paste0("^", date_part, "T[0-9]{2}:[0-9]{2}$")) ~ paste0(x, ":00"),    str_detect(x, paste0("^", date_part, "T[0-9]{2}:[0-9]{2}:[0-9]{2}")) ~ str_sub(x, 1, 19),    TRUE ~ x  )}baseline <- function(data, testcd, flag, value, tests) {  data %>%    transmute(      USUBJID,      TESTCD = .data[[testcd]],      FLAG = .data[[flag]],      VALUE = as.numeric(.data[[value]])    ) %>%    filter(FLAG %in% "Y", TESTCD %in% names(tests)) %>%    group_by(USUBJID, TESTCD) %>%    slice(1) %>%    ungroup() %>%    mutate(TESTCD = factor(unname(tests[TESTCD]), levels = unname(tests))) %>%    select(USUBJID, TESTCD, VALUE) %>%    pivot_wider(      names_from = TESTCD,      values_from = VALUE,      names_expand = TRUE    )}vs_bl <- baseline(  vs, "VSTESTCD", "VSBLFL", "VSSTRESN",  c(WEIGHT = "WTBL", HEIGHT = "HTBL"))lb_bl <- baseline(  lb, "LBTESTCD", "LBBLFL", "LBSTRESN",  c(CREAT = "CREATBL", ALT = "ALTBL", BILI = "TBILBL"))events <- bind_rows(  ex %>% transmute(USUBJID, ADTM = with_seconds(EXSTDTC), EVID = 1L),  pc %>% transmute(USUBJID, ADTM = with_seconds(PCDTC), EVID = 0L))adppk <- events %>%  inner_join(    adsl %>% transmute(STUDYID, USUBJID, AGE = as.numeric(AGE), SEX, RACE),    by = "USUBJID"  ) %>%  left_join(vs_bl, by = "USUBJID") %>%  left_join(lb_bl, by = "USUBJID") %>%  arrange(USUBJID, ADTM, desc(EVID)) %>%  group_by(USUBJID) %>%  mutate(ASEQ = row_number()) %>%  ungroup() %>%  mutate(    SEXN = case_when(SEX == "M" ~ 1L, SEX == "F" ~ 2L, TRUE ~ NA_integer_),    RACEN = case_when(      RACE %in% "ASIAN" ~ 2L,      RACE %in% "BLACK OR AFRICAN AMERICAN" ~ 3L,      RACE %in% "WHITE" ~ 5L,      TRUE ~ 6L    ),    BMIBL = WTBL / (HTBL / 100)^2,    BSABL = sqrt(HTBL * WTBL / 3600),    CRCLBL = (140 - AGE) * WTBL *      case_when(SEX == "M" ~ 1.23, SEX == "F" ~ 1.04, TRUE ~ NA_real_) /      CREATBL,    EGFR_R = CREATBL / 88.42 /      case_when(SEX == "M" ~ 0.9, SEX == "F" ~ 0.7, TRUE ~ NA_real_),    EGFR_A = case_when(      EGFR_R > 1 ~ -1.2,      SEX == "M" ~ -0.302,      SEX == "F" ~ -0.241,      TRUE ~ NA_real_    ),    EGFRBL = 142 * EGFR_R^EGFR_A * 0.9938^AGE *      case_when(SEX == "F" ~ 1.012, SEX == "M" ~ 1, TRUE ~ NA_real_)  ) %>%  select(    STUDYID, USUBJID, ASEQ, ADTM, EVID, AGE, SEX, SEXN, RACE, RACEN,    WTBL, HTBL, BMIBL, BSABL, CREATBL, ALTBL, TBILBL, CRCLBL, EGFRBL  )write_csv(adppk, file.path("/app/output", "adppk.csv"), na = "")

solutions/adam-adppk-baseline-covariates/result.py

Edit
107 lines
# Reference solution for the yamaa benchmark adam-adppk-baseline-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 numpy as npimport pandas as pdIN = "/app/input"OUT = "/app/output"KEYS = ["STUDYID", "USUBJID"]COLUMNS = [    "STUDYID", "USUBJID", "ASEQ", "ADTM", "EVID", "AGE", "SEX", "SEXN",    "RACE", "RACEN", "WTBL", "HTBL", "BMIBL", "BSABL", "CREATBL", "ALTBL",    "TBILBL", "CRCLBL", "EGFRBL",]def read(name):    return pd.read_csv(f"{IN}/{name}.csv", dtype=str, keep_default_na=False)def full_datetime(value):    value = value.strip()    if "T" not in value:        date, time = value, ""    else:        date, time = value.split("T", 1)    parts = [p for p in time.split(":") if p != ""]    parts = (parts + ["00", "00", "00"])[:3]    return f"{date}T{':'.join(parts)}"def baseline(df, testcd, flag, result, tests):    df = df[(df[flag].str.strip() == "Y") & df[testcd].str.strip().isin(tests)].copy()    df["_value"] = pd.to_numeric(df[result].str.strip().replace("", np.nan))    df["_name"] = df[testcd].str.strip().map(tests)    wide = df.groupby(KEYS + ["_name"], sort=False)["_value"].first().unstack("_name")    wide = wide.reindex(columns=list(tests.values()))    wide.columns.name = None    return wide.reset_index()adsl = read("adsl")ex = read("ex")pc = read("pc")vs = read("vs")lb = read("lb")doses = ex[KEYS].copy()doses["ADTM"] = ex["EXSTDTC"].map(full_datetime)doses["EVID"] = 1samples = pc[KEYS].copy()samples["ADTM"] = pc["PCDTC"].map(full_datetime)samples["EVID"] = 0events = pd.concat([doses, samples], ignore_index=True)events = events.sort_values(    KEYS + ["ADTM", "EVID"], ascending=[True, True, True, False], kind="stable").reset_index(drop=True)events["ASEQ"] = events.groupby(KEYS, sort=False).cumcount() + 1cov = adsl[KEYS + ["AGE", "SEX", "RACE"]].copy()cov["AGE"] = pd.to_numeric(cov["AGE"].str.strip().replace("", np.nan))cov["SEXN"] = cov["SEX"].map({"M": 1, "F": 2}).astype("Int64")cov["RACEN"] = (    cov["RACE"]    .map({"ASIAN": 2, "BLACK OR AFRICAN AMERICAN": 3, "WHITE": 5})    .fillna(6)    .astype("Int64"))cov = cov.merge(    baseline(vs, "VSTESTCD", "VSBLFL", "VSSTRESN", {"WEIGHT": "WTBL", "HEIGHT": "HTBL"}),    on=KEYS, how="left",)cov = cov.merge(    baseline(lb, "LBTESTCD", "LBBLFL", "LBSTRESN",             {"CREAT": "CREATBL", "ALT": "ALTBL", "BILI": "TBILBL"}),    on=KEYS, how="left",)male = cov["SEX"] == "M"female = cov["SEX"] == "F"known = male | femalecov["BMIBL"] = cov["WTBL"] / (cov["HTBL"] / 100) ** 2cov["BSABL"] = np.sqrt(cov["HTBL"] * cov["WTBL"] / 3600)cg = pd.Series(np.where(male, 1.23, 1.04), index=cov.index).where(known)cov["CRCLBL"] = (140 - cov["AGE"]) * cov["WTBL"] * cg / cov["CREATBL"]kappa = pd.Series(np.where(male, 0.9, 0.7), index=cov.index).where(known)ratio = cov["CREATBL"] / 88.42 / kappalow = pd.Series(np.where(male, -0.302, -0.241), index=cov.index)exponent = pd.Series(np.where(ratio > 1, -1.2, low), index=cov.index)sex_factor = pd.Series(np.where(female, 1.012, 1.0), index=cov.index)cov["EGFRBL"] = 142 * ratio ** exponent * 0.9938 ** cov["AGE"] * sex_factorif cov["AGE"].notna().all() and (cov["AGE"] % 1 == 0).all():    cov["AGE"] = cov["AGE"].astype("Int64")adppk = events.merge(cov, on=KEYS, how="left")[COLUMNS]adppk.to_csv(f"{OUT}/adppk.csv", index=False)

solutions/adam-adppk-baseline-covariates/result.sas

Edit
153 lines
/* opensas reference solution for the yamaa benchmark adam-adppk-baseline-covariates.   Reads the benchmark inputs and derives the requested output.   Execute with the existing opensas runtime: opensas /app/output/result.sas. */data adsl;  infile "/app/input/adsl.csv" dsd dlm=',' firstobs=2 truncover;  length STUDYID $20 USUBJID $40 AGE 8 AGEU $10 SEX $1 RACE $60;  input STUDYID $ USUBJID $ AGE AGEU $ SEX $ RACE $;  RACE = compress(RACE, "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 $25;  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 $20 PCDTC $25;  input STUDYID $ USUBJID $ PCSEQ PCTESTCD $ PCTPT $ PCDTC $;  PCDTC = compress(PCDTC, "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 LBBLFL $1 VISIT $20 LBDTC $25;  input STUDYID $ USUBJID $ LBSEQ LBTESTCD $ LBSTRESN LBSTRESU $ LBBLFL $ VISIT $ LBDTC $;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 VSBLFL $1 VISIT $20 VSDTC $25;  input STUDYID $ USUBJID $ VSSEQ VSTESTCD $ VSSTRESN VSSTRESU $ VSBLFL $ VISIT $ VSDTC $;run;proc sort data=vs out=vsb;  by STUDYID USUBJID VSSEQ;  where VSBLFL = "Y" and VSTESTCD in ("WEIGHT", "HEIGHT");run;data vsbl(keep=STUDYID USUBJID WTBL HTBL);  set vsb;  by STUDYID USUBJID;  retain WTBL HTBL;  if first.USUBJID then do; WTBL = .; HTBL = .; end;  if VSTESTCD = "WEIGHT" then WTBL = VSSTRESN;  else if VSTESTCD = "HEIGHT" then HTBL = VSSTRESN;  if last.USUBJID then output;run;proc sort data=lb out=lbb;  by STUDYID USUBJID LBSEQ;  where LBBLFL = "Y" and LBTESTCD in ("CREAT", "ALT", "BILI");run;data lbbl(keep=STUDYID USUBJID CREATBL ALTBL TBILBL);  set lbb;  by STUDYID USUBJID;  retain CREATBL ALTBL TBILBL;  if first.USUBJID then do; CREATBL = .; ALTBL = .; TBILBL = .; end;  if LBTESTCD = "CREAT" then CREATBL = LBSTRESN;  else if LBTESTCD = "ALT" then ALTBL = LBSTRESN;  else if LBTESTCD = "BILI" then TBILBL = LBSTRESN;  if last.USUBJID then output;run;proc sort data=adsl; by STUDYID USUBJID; run;data cov;  merge adsl(in=a keep=STUDYID USUBJID AGE SEX RACE) vsbl lbbl;  by STUDYID USUBJID;  if a;  length SEXN RACEN BMIBL BSABL CRCLBL EGFRBL 8;  if SEX = "M" then SEXN = 1;  else if SEX = "F" then SEXN = 2;  if RACE = "ASIAN" then RACEN = 2;  else if RACE = "BLACK OR AFRICAN AMERICAN" then RACEN = 3;  else if RACE = "WHITE" then RACEN = 5;  else RACEN = 6;  if not missing(WTBL) and not missing(HTBL) then do;    BMIBL = WTBL / ((HTBL / 100) ** 2);    BSABL = sqrt(HTBL * WTBL / 3600);  end;  if not missing(AGE) and not missing(WTBL) and not missing(CREATBL) then do;    if SEX = "M" then CRCLBL = (140 - AGE) * WTBL * 1.23 / CREATBL;    else if SEX = "F" then CRCLBL = (140 - AGE) * WTBL * 1.04 / CREATBL;  end;  if not missing(AGE) and not missing(CREATBL) then do;    if SEX = "M" then do;      r = CREATBL / 88.42 / 0.9;      if r > 1 then ex_a = -1.2; else ex_a = -0.302;      EGFRBL = 142 * (r ** ex_a) * (0.9938 ** AGE);    end;    else if SEX = "F" then do;      r = CREATBL / 88.42 / 0.7;      if r > 1 then ex_a = -1.2; else ex_a = -0.241;      EGFRBL = 142 * (r ** ex_a) * (0.9938 ** AGE) * 1.012;    end;  end;  drop r ex_a;run;data events(keep=STUDYID USUBJID ADTM EVID SRCSEQ);  length STUDYID $20 USUBJID $40 ADTM $19 EVID 8 SRCSEQ 8 dtc $25;  set ex(in=inex keep=STUDYID USUBJID EXSEQ EXSTDTC) pc(keep=STUDYID USUBJID PCSEQ PCDTC);  if inex then do; EVID = 1; dtc = EXSTDTC; SRCSEQ = EXSEQ; end;  else do; EVID = 0; dtc = PCDTC; SRCSEQ = PCSEQ; end;  dtc = strip(dtc);  if length(dtc) = 16 then ADTM = cats(dtc, ":00");  else ADTM = dtc;run;proc sort data=events;  by STUDYID USUBJID ADTM descending EVID SRCSEQ;run;data adppk;  retain STUDYID USUBJID ASEQ ADTM EVID AGE SEX SEXN RACE RACEN WTBL HTBL         BMIBL BSABL CREATBL ALTBL TBILBL CRCLBL EGFRBL;  merge events(in=e) cov;  by STUDYID USUBJID;  if e;  if first.USUBJID then ASEQ = 0;  ASEQ + 1;  keep STUDYID USUBJID ASEQ ADTM EVID AGE SEX SEXN RACE RACEN WTBL HTBL       BMIBL BSABL CREATBL ALTBL TBILBL CRCLBL EGFRBL;run;data _null_;  set adppk;  file "/app/output/adppk.csv";  length line $600 v $40;  array nums{14} ASEQ EVID AGE SEXN RACEN WTBL HTBL BMIBL BSABL CREATBL ALTBL TBILBL CRCLBL EGFRBL;  array txt{14} $40 t1-t14;  do i = 1 to 14;    if missing(nums{i}) then txt{i} = "";    else do;      v = strip(put(nums{i}, best32.));      if index(v, "E") > 0 then v = strip(put(nums{i}, best16.));      txt{i} = v;    end;  end;  if _n_ = 1 then put "STUDYID,USUBJID,ASEQ,ADTM,EVID,AGE,SEX,SEXN,RACE,RACEN,WTBL,HTBL,BMIBL,BSABL,CREATBL,ALTBL,TBILBL,CRCLBL,EGFRBL";  line = trimn(STUDYID) || "," || trimn(USUBJID) || "," || trimn(t1) || "," || trimn(ADTM) || "," ||         trimn(t2) || "," || trimn(t3) || "," || trimn(SEX) || "," || trimn(t4) || "," ||         trimn(RACE) || "," || trimn(t5);  do i = 6 to 14;    line = trimn(line) || "," || trimn(txt{i});  end;  put line;run;