As a clinical trial statistician or programmer, challenge anything in this benchmark: describe a problem in Comments, or propose a fix with the Edit button on any source file.
- Task: Would a real study need this derivation, specified this way? Does it follow CDISC SDTM: variable names, controlled terms, record structure? Flag any rule that is ambiguous or that a sponsor would handle differently.
- Inputs: Do they look like data collected in a real trial, and do they include the situations you would expect to meet in one?
- Expected output: Would independent QC programming reproduce every value from these inputs and rules?
The other tabs beside Comments are background for assessment, not under review.
Summary
README.mdGoal: build one Disposition (DS) record per subject
for each of four study events carried in a single ODM
item extract: informed consent and randomization as
protocol milestones, and end of treatment and end of
study as disposition events. Each event gives its own
reported term (DSTERM), controlled term (DSDECOD),
category (DSCAT), subcategory (DSSCAT) and date
(DSSTDTC), with DSSEQ numbering each subject's
records in the order they happened.
Input: one ODM file (input/odm.csv) with one row
per collected item value, keyed by study, subject,
study event, form and item. The four study events are
CONSENT, RAND, EOT and EOS; every form carries
a date item (IT.DS.DTC), and the treatment and study
forms also carry a completion status (IT.DS.COMP), a
reported reason (IT.DS.REASON) and a standardized
reason (IT.DS.REASONCD).
Variables:
DSSEQnumbers each subject's records in the order they happened, byDSSTDTCand then byDSTERM, so records on the same day keep a fixed order. WithSTUDYIDandUSUBJIDit identifies the record.DSTERMholds the reported term: the controlled term for a milestone;COMPLETEDwhen the completion status says so, orSCREEN FAILUREat end of study when it says so; else the collected reason.DSDECODholds the controlled term: the same term asDSTERMfor a milestone, a completion or a screen failure, else the collected standardized reason.DSCATfollows the event, not the term:PROTOCOL MILESTONEfor consent and randomization,DISPOSITION EVENTfor end of treatment and end of study.DSSCATnames the event:INFORMED CONSENT,RANDOMIZATION,END OF TREATMENTorEND OF STUDY.DSSTDTCis the collected date item for that record.
Note: each collected form gives one record and an event with no form gives none, so a screen failure has only its consent and end-of-study records.
Provenance: DSCAT/DSSCAT/DSTERM/DSDECOD follow
the CDISC SDTMIG DS assumptions (protocol milestones
carry the same value in DSTERM and DSDECOD), and the
controlled terms follow the FDA Technical Conformance
Guide DS guidance. All subjects, dates and reasons are
invented fixtures.
Inputs
Under review1 source fileinput/odm.csv
Edit40 rows| StudyOID | MetaDataVersionOID | SubjectKey | StudyEventOID | StudyEventRepeatKey | ItemGroupOID | ItemGroupRepeatKey | ItemOID | Value |
|---|---|---|---|---|---|---|---|---|
| YAMAA-01 | MDV.1 | 001 | CONSENT | 1 | IG.DS | 1 | IT.DS.DTC | 2024-01-05 |
| YAMAA-01 | MDV.1 | 001 | CONSENT | 1 | IG.DS | 1 | IT.DS.COMP | — |
| YAMAA-01 | MDV.1 | 001 | CONSENT | 1 | IG.DS | 1 | IT.DS.REASON | — |
| YAMAA-01 | MDV.1 | 001 | CONSENT | 1 | IG.DS | 1 | IT.DS.REASONCD | — |
| YAMAA-01 | MDV.1 | 001 | RAND | 1 | IG.DS | 1 | IT.DS.DTC | 2024-01-05 |
| YAMAA-01 | MDV.1 | 001 | RAND | 1 | IG.DS | 1 | IT.DS.COMP | — |
| YAMAA-01 | MDV.1 | 001 | RAND | 1 | IG.DS | 1 | IT.DS.REASON | — |
| YAMAA-01 | MDV.1 | 001 | RAND | 1 | IG.DS | 1 | IT.DS.REASONCD | — |
| YAMAA-01 | MDV.1 | 001 | EOT | 1 | IG.DS | 1 | IT.DS.DTC | 2024-06-10 |
| YAMAA-01 | MDV.1 | 001 | EOT | 1 | IG.DS | 1 | IT.DS.COMP | COMPLETED |
| YAMAA-01 | MDV.1 | 001 | EOT | 1 | IG.DS | 1 | IT.DS.REASON | — |
| YAMAA-01 | MDV.1 | 001 | EOT | 1 | IG.DS | 1 | IT.DS.REASONCD | — |
| YAMAA-01 | MDV.1 | 001 | EOS | 1 | IG.DS | 1 | IT.DS.DTC | 2024-07-15 |
| YAMAA-01 | MDV.1 | 001 | EOS | 1 | IG.DS | 1 | IT.DS.COMP | COMPLETED |
| YAMAA-01 | MDV.1 | 001 | EOS | 1 | IG.DS | 1 | IT.DS.REASON | — |
| YAMAA-01 | MDV.1 | 001 | EOS | 1 | IG.DS | 1 | IT.DS.REASONCD | — |
| YAMAA-01 | MDV.1 | 002 | CONSENT | 1 | IG.DS | 1 | IT.DS.DTC | 2024-01-08 |
| YAMAA-01 | MDV.1 | 002 | CONSENT | 1 | IG.DS | 1 | IT.DS.COMP | — |
| YAMAA-01 | MDV.1 | 002 | CONSENT | 1 | IG.DS | 1 | IT.DS.REASON | — |
| YAMAA-01 | MDV.1 | 002 | CONSENT | 1 | IG.DS | 1 | IT.DS.REASONCD | — |
| YAMAA-01 | MDV.1 | 002 | RAND | 1 | IG.DS | 1 | IT.DS.DTC | 2024-01-09 |
| YAMAA-01 | MDV.1 | 002 | RAND | 1 | IG.DS | 1 | IT.DS.COMP | — |
| YAMAA-01 | MDV.1 | 002 | RAND | 1 | IG.DS | 1 | IT.DS.REASON | — |
| YAMAA-01 | MDV.1 | 002 | RAND | 1 | IG.DS | 1 | IT.DS.REASONCD | — |
| YAMAA-01 | MDV.1 | 002 | EOT | 1 | IG.DS | 1 | IT.DS.DTC | 2024-03-20 |
| YAMAA-01 | MDV.1 | 002 | EOT | 1 | IG.DS | 1 | IT.DS.COMP | DISCONTINUED |
| YAMAA-01 | MDV.1 | 002 | EOT | 1 | IG.DS | 1 | IT.DS.REASON | Severe nausea |
| YAMAA-01 | MDV.1 | 002 | EOT | 1 | IG.DS | 1 | IT.DS.REASONCD | ADVERSE EVENT |
| YAMAA-01 | MDV.1 | 002 | EOS | 1 | IG.DS | 1 | IT.DS.DTC | 2024-03-25 |
| YAMAA-01 | MDV.1 | 002 | EOS | 1 | IG.DS | 1 | IT.DS.COMP | DISCONTINUED |
| YAMAA-01 | MDV.1 | 002 | EOS | 1 | IG.DS | 1 | IT.DS.REASON | Subject moved |
| YAMAA-01 | MDV.1 | 002 | EOS | 1 | IG.DS | 1 | IT.DS.REASONCD | LOST TO FOLLOW-UP |
| YAMAA-01 | MDV.1 | 003 | CONSENT | 1 | IG.DS | 1 | IT.DS.DTC | 2024-01-12 |
| YAMAA-01 | MDV.1 | 003 | CONSENT | 1 | IG.DS | 1 | IT.DS.COMP | — |
| YAMAA-01 | MDV.1 | 003 | CONSENT | 1 | IG.DS | 1 | IT.DS.REASON | — |
| YAMAA-01 | MDV.1 | 003 | CONSENT | 1 | IG.DS | 1 | IT.DS.REASONCD | — |
| YAMAA-01 | MDV.1 | 003 | EOS | 1 | IG.DS | 1 | IT.DS.DTC | 2024-01-14 |
| YAMAA-01 | MDV.1 | 003 | EOS | 1 | IG.DS | 1 | IT.DS.COMP | SCREEN FAILURE |
| YAMAA-01 | MDV.1 | 003 | EOS | 1 | IG.DS | 1 | IT.DS.REASON | — |
| YAMAA-01 | MDV.1 | 003 | EOS | 1 | IG.DS | 1 | IT.DS.REASONCD | — |
Expected output
Under review10 expected rowsexpected/ds.csv
Edit10 rows| DOMAIN | STUDYID | USUBJID | DSSEQ | DSTERM | DSDECOD | DSCAT | DSSCAT | DSSTDTC |
|---|---|---|---|---|---|---|---|---|
| DS | YAMAA-01 | 1 | INFORMED CONSENT OBTAINED | INFORMED CONSENT OBTAINED | PROTOCOL MILESTONE | INFORMED CONSENT | 2024-01-05 | |
| DS | YAMAA-01 | 2 | RANDOMIZED | RANDOMIZED | PROTOCOL MILESTONE | RANDOMIZATION | 2024-01-05 | |
| DS | YAMAA-01 | 3 | COMPLETED | COMPLETED | DISPOSITION EVENT | END OF TREATMENT | 2024-06-10 | |
| DS | YAMAA-01 | 4 | COMPLETED | COMPLETED | DISPOSITION EVENT | END OF STUDY | 2024-07-15 | |
| DS | YAMAA-01 | 1 | INFORMED CONSENT OBTAINED | INFORMED CONSENT OBTAINED | PROTOCOL MILESTONE | INFORMED CONSENT | 2024-01-08 | |
| DS | YAMAA-01 | 2 | RANDOMIZED | RANDOMIZED | PROTOCOL MILESTONE | RANDOMIZATION | 2024-01-09 | |
| DS | YAMAA-01 | 3 | Severe nausea | ADVERSE EVENT | DISPOSITION EVENT | END OF TREATMENT | 2024-03-20 | |
| DS | YAMAA-01 | 4 | Subject moved | LOST TO FOLLOW-UP | DISPOSITION EVENT | END OF STUDY | 2024-03-25 | |
| DS | YAMAA-01 | 1 | INFORMED CONSENT OBTAINED | INFORMED CONSENT OBTAINED | PROTOCOL MILESTONE | INFORMED CONSENT | 2024-01-12 | |
| DS | YAMAA-01 | 2 | SCREEN FAILURE | SCREEN FAILURE | DISPOSITION EVENT | END OF STUDY | 2024-01-14 |
Comments and assessment materials
| Variable Name | Variable Label | Type | Length | Controlled Terms or Format | Origin | Core | Conversion Definition | Variable Type | Variable Order | Comments for Define |
|---|---|---|---|---|---|---|---|---|---|---|
| DOMAIN | Domain Abbreviation | Char | DS | Assigned | Set constant value "DS". | SDTM | 1 | |||
| STUDYID | Study Identifier | Char | Collected | Copy value from ODM.StudyOID. | SDTM | 2 | ||||
| USUBJID | Unique Subject Identifier | Char | Derived | Fill the template "{STUDYID}-{SUBJKEY}". | SDTM | 3 | ||||
| DSTERM | Reported Term for the Disposition Event | Char | Derived | Set per constructed row; see the Row construction sheet. | SDTM | 4 | ||||
| DSDECOD | Standardized Disposition Term | Char | INFORMED CONSENT OBTAINED, RANDOMIZED, COMPLETED, ADVERSE EVENT, LOST TO FOLLOW-UP, SCREEN FAILURE | Derived | Set per constructed row; see the Row construction sheet. | SDTM | 5 | |||
| DSCAT | Category for Disposition Event | Char | PROTOCOL MILESTONE, DISPOSITION EVENT | Derived | Set per constructed row; see the Row construction sheet. | SDTM | 6 | |||
| DSSCAT | Subcategory for Disposition Event | Char | INFORMED CONSENT, RANDOMIZATION, END OF TREATMENT, END OF STUDY | Derived | Set per constructed row; see the Row construction sheet. | SDTM | 7 | |||
| DSSTDTC | Start Date/Time of Disposition Event | Char | ISO 8601 | Derived | Set per constructed row; see the Row construction sheet. | SDTM | 8 | |||
| DSSEQ | Sequence Number | Num | Derived | Row number within each group of STUDYID, USUBJID, ordered by DSSTDTC then DSTERM. | SDTM | 9 |
| Template | Include when | EVENT | COMPSTAT | DSTERM | DSDECOD | DSCAT | DSSCAT | DSSTDTC |
|---|---|---|---|---|---|---|---|---|
| consent | EVENT = 'CONSENT' | Copy ODM.StudyEventOID | Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.COMP' | Constant "INFORMED CONSENT OBTAINED" | Constant "INFORMED CONSENT OBTAINED" | Constant "PROTOCOL MILESTONE" | Constant "INFORMED CONSENT" | Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.DTC' |
| randomization | EVENT = 'RAND' | Copy ODM.StudyEventOID | Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.COMP' | Constant "RANDOMIZED" | Constant "RANDOMIZED" | Constant "PROTOCOL MILESTONE" | Constant "RANDOMIZATION" | Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.DTC' |
| end_of_treatment | EVENT = 'EOT' | Copy ODM.StudyEventOID | Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.COMP' | If COMPSTAT = 'COMPLETED' then "COMPLETED"; otherwise aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.REASON' | If COMPSTAT = 'COMPLETED' then "COMPLETED"; otherwise aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.REASONCD' | Constant "DISPOSITION EVENT" | Constant "END OF TREATMENT" | Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.DTC' |
| end_of_study | EVENT = 'EOS' | Copy ODM.StudyEventOID | Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.COMP' | If COMPSTAT = 'COMPLETED' then "COMPLETED"; If COMPSTAT = 'SCREEN FAILURE' then "SCREEN FAILURE"; otherwise aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.REASON' | If COMPSTAT = 'COMPLETED' then "COMPLETED"; If COMPSTAT = 'SCREEN FAILURE' then "SCREEN FAILURE"; otherwise aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.REASONCD' | Constant "DISPOSITION EVENT" | Constant "END OF STUDY" | Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.DTC' |
| Variable | Permitted values |
|---|---|
| DOMAIN | DS |
| DSDECOD | INFORMED CONSENT OBTAINED, RANDOMIZED, COMPLETED, ADVERSE EVENT, LOST TO FOLLOW-UP, SCREEN FAILURE |
| DSCAT | PROTOCOL MILESTONE, DISPOSITION EVENT |
| DSSCAT | INFORMED CONSENT, RANDOMIZATION, END OF TREATMENT, END OF STUDY |
| Version | Date | Author | Description | Reviewer | Sign-off |
|---|---|---|---|---|---|
| 1.3 | 2026-09-29 | yamaa docs build | Show study codelist names, external dictionaries, and ISO 8601 formats in variable rows; list the document's codelist values and metadata | ||
| 1.2 | 2026-09-29 | yamaa docs build | Classify ADaM copies from a declared input as Predecessor and recodes as Derived, and SDTM recodes of locally derived columns as Derived | ||
| 1.1 | 2026-09-29 | yamaa docs build | Resolve lookups into the donor record they select, and give every derivation shape a plain-language rule instead of its raw YAML | ||
| 1.0 | yamaa docs build | Initial generation from spec.yaml |
prompts/sdtm-ds-multi-form-disposition/full.md
Edit23 linesFollowing CDISC SDTM standards, use the provided ODM dataset to create a DS dataset with one record per subject per study event: informed consent, randomization, end of treatment, and end of study.
The output dataset should contain the following columns in this order: DOMAIN, STUDYID, USUBJID, DSSEQ, DSTERM, DSDECOD, DSCAT, DSSCAT, DSSTDTC
USUBJID is the study and subject identifiers with a hyphen between them. Each collected form gives one record, and an event with no form gives none. Consent gives DSTERM and DSDECOD INFORMED CONSENT OBTAINED; randomization gives RANDOMIZED. Both are protocol milestones, with DSSCAT INFORMED CONSENT and RANDOMIZATION. End of treatment gives COMPLETED when the completion status says so, else the collected reason with the collected standardized reason; DSSCAT is END OF TREATMENT. End of study gives COMPLETED when completed, SCREEN FAILURE when the status says so, else the collected reason with the collected standardized reason; DSSCAT is END OF STUDY. End-of-treatment and end-of-study records are disposition events. DSSTDTC is the collected date for that record. DSSEQ numbers each subject's records in the order they happened, by date and then by reported term.
Read the source datasets from /app/input and save the completed dataset as /app/output/ds.csv.
prompts/sdtm-ds-multi-form-disposition/conventions.md
Edit17 linesFollowing CDISC SDTM standards, use the provided ODM dataset to create a DS dataset with one record per subject per study event: informed consent, randomization, end of treatment, and end of study.
The output dataset should contain the following columns in this order: DOMAIN, STUDYID, USUBJID, DSSEQ, DSTERM, DSDECOD, DSCAT, DSSCAT, DSSTDTC
Consent gives DSTERM and DSDECOD INFORMED CONSENT OBTAINED; randomization gives RANDOMIZED. Both are protocol milestones, with DSSCAT INFORMED CONSENT and RANDOMIZATION. End of treatment gives COMPLETED or the collected reason with the collected standardized reason; DSSCAT is END OF TREATMENT. End of study gives COMPLETED, SCREEN FAILURE, or the collected reason with the collected standardized reason; DSSCAT is END OF STUDY. End-of-treatment and end-of-study records are disposition events.
Read the source datasets from /app/input and save the completed dataset as /app/output/ds.csv.
prompts/sdtm-ds-multi-form-disposition/brief.md
Edit9 linesFollowing CDISC SDTM standards, use the provided ODM dataset to create a DS dataset with one record per subject per study event: informed consent, randomization, end of treatment, and end of study.
The output dataset should contain the following columns in this order: DOMAIN, STUDYID, USUBJID, DSSEQ, DSTERM, DSDECOD, DSCAT, DSSCAT, DSSTDTC
Read the source datasets from /app/input and save the completed dataset as /app/output/ds.csv.
run.R
Edit4 lineslibrary(yamaa)ds <- yamaa_domain("spec.yaml")$outputdsrun.py
Edit4 linesimport yamaads = yamaa.yamaa_domain("spec.yaml").outputdssolutions/sdtm-ds-multi-form-disposition/result.R
Edit79 lines# Reference solution for the yamaa benchmark sdtm-ds-multi-form-disposition (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(tidyr)odm <- read_csv( "/app/input/odm.csv", col_types = cols(.default = col_character()))wide <- odm |> group_by(StudyOID, SubjectKey, StudyEventOID) |> summarise( DTC = Value[ItemOID == "IT.DS.DTC"][1], COMP = Value[ItemOID == "IT.DS.COMP"][1], REASON = Value[ItemOID == "IT.DS.REASON"][1], REASONCD = Value[ItemOID == "IT.DS.REASONCD"][1], .groups = "drop" )ds <- wide |> rowwise() |> mutate( DSTERM = case_when( StudyEventOID == "CONSENT" ~ "INFORMED CONSENT OBTAINED", StudyEventOID == "RAND" ~ "RANDOMIZED", StudyEventOID == "EOT" & COMP == "COMPLETED" ~ "COMPLETED", StudyEventOID == "EOT" ~ REASON, StudyEventOID == "EOS" & COMP == "COMPLETED" ~ "COMPLETED", StudyEventOID == "EOS" & COMP == "SCREEN FAILURE" ~ "SCREEN FAILURE", StudyEventOID == "EOS" ~ REASON, .default = NA_character_ ), DSDECOD = case_when( StudyEventOID == "CONSENT" ~ "INFORMED CONSENT OBTAINED", StudyEventOID == "RAND" ~ "RANDOMIZED", StudyEventOID == "EOT" & COMP == "COMPLETED" ~ "COMPLETED", StudyEventOID == "EOT" ~ REASONCD, StudyEventOID == "EOS" & COMP == "COMPLETED" ~ "COMPLETED", StudyEventOID == "EOS" & COMP == "SCREEN FAILURE" ~ "SCREEN FAILURE", StudyEventOID == "EOS" ~ REASONCD, .default = NA_character_ ), DSCAT = case_when( StudyEventOID %in% c("CONSENT", "RAND") ~ "PROTOCOL MILESTONE", StudyEventOID %in% c("EOT", "EOS") ~ "DISPOSITION EVENT", .default = NA_character_ ), DSSCAT = case_when( StudyEventOID == "CONSENT" ~ "INFORMED CONSENT", StudyEventOID == "RAND" ~ "RANDOMIZATION", StudyEventOID == "EOT" ~ "END OF TREATMENT", StudyEventOID == "EOS" ~ "END OF STUDY", .default = NA_character_ ) ) |> ungroup() |> filter(StudyEventOID %in% c("CONSENT", "RAND", "EOT", "EOS")) |> mutate( DOMAIN = "DS", STUDYID = StudyOID, USUBJID = paste(StudyOID, SubjectKey, sep = "-"), DSSTDTC = suppressWarnings(as.Date(na_if(DTC, ""))), DSTERM = na_if(DSTERM, ""), DSDECOD = na_if(DSDECOD, "") ) |> arrange(USUBJID, DSSTDTC, DSTERM) |> group_by(USUBJID) |> mutate(DSSEQ = row_number()) |> ungroup() |> select(DOMAIN, STUDYID, USUBJID, DSSEQ, DSTERM, DSDECOD, DSCAT, DSSCAT, DSSTDTC)dir.create("/app/output", showWarnings = FALSE)write_csv(ds, "/app/output/ds.csv", na = "")solutions/sdtm-ds-multi-form-disposition/result.py
Edit126 lines# Reference solution for the yamaa benchmark sdtm-ds-multi-form-disposition (Python track).## Written from the benchmark's full prompt and its inputs alone, as an agent# would write it. Harbor's oracle agent runs it to check that the prompt can# be solved and that the grader scores a correct answer 1.from pathlib import Pathimport polars as plodm = pl.read_csv("/app/input/odm.csv", infer_schema=False)wide = ( odm.group_by("StudyOID", "SubjectKey", "StudyEventOID") .agg( pl.col("Value").filter(pl.col("ItemOID") == "IT.DS.DTC").first().alias("DTC"), pl.col("Value").filter(pl.col("ItemOID") == "IT.DS.COMP").first().alias("COMP"), pl.col("Value").filter(pl.col("ItemOID") == "IT.DS.REASON").first().alias("REASON"), pl.col("Value") .filter(pl.col("ItemOID") == "IT.DS.REASONCD") .first() .alias("REASONCD"), ))def build_row(event: str, dtc, comp, reason, reasoncd) -> dict | None: if event == "CONSENT": return { "DSTERM": "INFORMED CONSENT OBTAINED", "DSDECOD": "INFORMED CONSENT OBTAINED", "DSCAT": "PROTOCOL MILESTONE", "DSSCAT": "INFORMED CONSENT", } if event == "RAND": return { "DSTERM": "RANDOMIZED", "DSDECOD": "RANDOMIZED", "DSCAT": "PROTOCOL MILESTONE", "DSSCAT": "RANDOMIZATION", } if event == "EOT": if comp == "COMPLETED": term, decod = "COMPLETED", "COMPLETED" else: term, decod = reason, reasoncd return { "DSTERM": term, "DSDECOD": decod, "DSCAT": "DISPOSITION EVENT", "DSSCAT": "END OF TREATMENT", } if event == "EOS": if comp == "COMPLETED": term, decod = "COMPLETED", "COMPLETED" elif comp == "SCREEN FAILURE": term, decod = "SCREEN FAILURE", "SCREEN FAILURE" else: term, decod = reason, reasoncd return { "DSTERM": term, "DSDECOD": decod, "DSCAT": "DISPOSITION EVENT", "DSSCAT": "END OF STUDY", } return Nonerecords: list[dict] = []for row in wide.to_dicts(): study = row["StudyOID"] subj = row["SubjectKey"] event = row["StudyEventOID"] out = build_row(event, row["DTC"], row["COMP"], row["REASON"], row["REASONCD"]) if out is None: continue usubjid = f"{study}-{subj}" records.append( { "STUDYID": study, "USUBJID": usubjid, "DSTERM": out["DSTERM"] if out["DSTERM"] != "" else None, "DSDECOD": out["DSDECOD"] if out["DSDECOD"] != "" else None, "DSCAT": out["DSCAT"], "DSSCAT": out["DSSCAT"], "DSSTDTC": row["DTC"] if row["DTC"] != "" else None, } )ds = pl.DataFrame( records, schema={ "STUDYID": pl.String, "USUBJID": pl.String, "DSTERM": pl.String, "DSDECOD": pl.String, "DSCAT": pl.String, "DSSCAT": pl.String, "DSSTDTC": pl.String, },).with_columns( DOMAIN=pl.lit("DS"), DSSTDTC_DT=pl.col("DSSTDTC").str.to_date(strict=False),)ds = ( ds.sort(["USUBJID", "DSSTDTC_DT", "DSTERM"]) .with_columns( DSSEQ=pl.col("USUBJID").cum_count().over("USUBJID"), ) .with_columns(DSSEQ=pl.col("DSSEQ").cast(pl.Int64)) .select( "DOMAIN", "STUDYID", "USUBJID", "DSSEQ", "DSTERM", "DSDECOD", "DSCAT", "DSSCAT", "DSSTDTC", ))Path("/app/output").mkdir(exist_ok=True)ds.write_csv("/app/output/ds.csv")solutions/sdtm-ds-multi-form-disposition/result.sas
Edit44 lines/* opensas reference solution for the yamaa benchmark sdtm-ds-multi-form-disposition. Reads the benchmark inputs and derives the requested output. Execute with the existing opensas runtime: opensas /app/output/result.sas. */data odm; length StudyOID MetaDataVersionOID SubjectKey StudyEventOID StudyEventRepeatKey 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. ItemGroupOID : $char1024. ItemGroupRepeatKey : $char1024. ItemOID : $char1024. Value : $char1024.;run;proc sort data=odm out=ordered; by StudyOID SubjectKey StudyEventOID; run;data wide; length COMP DTC REASON REASONCD $1024; retain COMP DTC REASON REASONCD; set ordered; by StudyOID SubjectKey StudyEventOID; if first.StudyEventOID then do; COMP=''; DTC=''; REASON=''; REASONCD=''; end; if ItemOID='IT.DS.COMP' then COMP=Value; if ItemOID='IT.DS.DTC' then DTC=Value; if ItemOID='IT.DS.REASON' then REASON=Value; if ItemOID='IT.DS.REASONCD' then REASONCD=Value; if last.StudyEventOID then output;run;data prepared; set wide; length DOMAIN $2 STUDYID USUBJID DSTERM DSDECOD DSCAT DSSCAT DSSTDTC $1024;DOMAIN='DS'; STUDYID=StudyOID; USUBJID=SubjectKey; DSCAT='DISPOSITION EVENT'; DSSTDTC=DTC; DSTERM=REASON; DSDECOD=REASONCD;if COMP='COMPLETED' then do; DSTERM='COMPLETED'; DSDECOD='COMPLETED'; end;USUBJID=catx('-',StudyOID,SubjectKey);if StudyEventOID='CONSENT' then do; DSTERM='INFORMED CONSENT OBTAINED'; DSDECOD=DSTERM; DSCAT='PROTOCOL MILESTONE'; DSSCAT='INFORMED CONSENT'; end;if StudyEventOID='RAND' then do; DSTERM='RANDOMIZED'; DSDECOD=DSTERM; DSCAT='PROTOCOL MILESTONE'; DSSCAT='RANDOMIZATION'; end;if StudyEventOID='EOT' then DSSCAT='END OF TREATMENT';if StudyEventOID='EOS' then do; DSSCAT='END OF STUDY'; if COMP='SCREEN FAILURE' then do; DSTERM='SCREEN FAILURE'; DSDECOD=DSTERM; end; end; run;proc sort data=prepared; by STUDYID USUBJID DSSTDTC DSTERM; run;data result; set prepared; by STUDYID USUBJID; retain DSSEQ; if first.USUBJID then DSSEQ=0; DSSEQ+1;run;proc sql; create table final as select DOMAIN, STUDYID, USUBJID, DSSEQ, DSTERM, DSDECOD, DSCAT, DSSCAT, DSSTDTC from result;quit;proc export data=final outfile="/app/output/ds.csv" dbms=csv replace; run;
yamaa
Comments
Signed in with GitHub; saved in repository Discussions