Review ask

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.

  1. 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.
  2. Inputs: Do they look like data collected in a real trial, and do they include the situations you would expect to meet in one?
  3. 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

Lifecycle: draftEditUnder review
What this benchmark means
README.md

Goal: build the CM record for each collected medication from the concomitant-medication form, carrying the reported name, indication, dose, frequency, route, and dates as collected, and the form's "taken before study" and "ongoing" boxes as timing references instead of invented dates.

Input: the medication log for two subjects: each medication is one repeat of the IG.CM item group, and the repeat number becomes CMSEQ. The dose is collected as free text, and the frequency and route as the labels printed on the form (Once daily, Twice daily, By mouth). One subject reports a single medication with complete dates and a single dose; the other reports a medication started before the study with only year and month known and the "ongoing" box checked, plus a medication whose dose was collected as a range.

Variables:

  • CMTRT is the medication name as reported, kept exactly as written.
  • CMINDC is the indication as reported.
  • CMDOSE is the collected dose when it is a plain number, such as 100; empty otherwise.
  • CMDOSTXT is the collected dose when it is not a plain number, such as the range 200-400; empty when CMDOSE carries the dose.
  • CMDOSU is the unit of the collected dose.
  • CMDOSFRQ is the collected frequency label mapped to controlled terminology: Once daily becomes QD and Twice daily becomes BID.
  • CMROUTE is the collected route label mapped to controlled terminology: By mouth becomes ORAL.
  • CMSTDTC is the start of the medication as collected, keeping partial dates at their collected precision: year and month alone stay 2023-09.
  • CMENDTC is the end of the medication as collected; empty when no end date was collected.
  • CMSTRTPT is BEFORE when the "taken before study" box is checked, and CMSTTPT names the reference point, SCREENING; both empty otherwise.
  • CMENRTPT is ONGOING when the "ongoing" box is checked, and CMENTPT names the reference point, END OF STUDY; both empty otherwise.

Note: a frequency or route label the mappings do not list stops the run rather than passing through unmapped. An ongoing medication has no end date, and CMENRTPT records why, so an empty CMENDTC is never left to stand for "ongoing" on its own.

Inputs

Under review
1 source file

input/odm.csv

Edit
29 rows
input/odm.csv
StudyOIDMetaDataVersionOIDSubjectKeyStudyEventOIDStudyEventRepeatKeyItemGroupOIDItemGroupRepeatKeyItemOIDValue
YAMAA-01MDV.1YAMAA-01-001TREATMENT1IG.CM1IT.CM.CMTRTASPIRIN
YAMAA-01MDV.1YAMAA-01-001TREATMENT1IG.CM1IT.CM.CMINDCHeadache
YAMAA-01MDV.1YAMAA-01-001TREATMENT1IG.CM1IT.CM.CMDSTXT100
YAMAA-01MDV.1YAMAA-01-001TREATMENT1IG.CM1IT.CM.CMDOSUmg
YAMAA-01MDV.1YAMAA-01-001TREATMENT1IG.CM1IT.CM.CMDOSFRQOnce daily
YAMAA-01MDV.1YAMAA-01-001TREATMENT1IG.CM1IT.CM.CMROUTEBy mouth
YAMAA-01MDV.1YAMAA-01-001TREATMENT1IG.CM1IT.CM.CMSTDTC2024-03-05
YAMAA-01MDV.1YAMAA-01-001TREATMENT1IG.CM1IT.CM.CMENDTC2024-03-12
YAMAA-01MDV.1YAMAA-01-001TREATMENT1IG.CM1IT.CM.CMPRIORN
YAMAA-01MDV.1YAMAA-01-001TREATMENT1IG.CM1IT.CM.CMONGON
YAMAA-01MDV.1YAMAA-01-002TREATMENT1IG.CM1IT.CM.CMTRTLISINOPRIL
YAMAA-01MDV.1YAMAA-01-002TREATMENT1IG.CM1IT.CM.CMINDCHypertension
YAMAA-01MDV.1YAMAA-01-002TREATMENT1IG.CM1IT.CM.CMDSTXT10
YAMAA-01MDV.1YAMAA-01-002TREATMENT1IG.CM1IT.CM.CMDOSUmg
YAMAA-01MDV.1YAMAA-01-002TREATMENT1IG.CM1IT.CM.CMDOSFRQOnce daily
YAMAA-01MDV.1YAMAA-01-002TREATMENT1IG.CM1IT.CM.CMROUTEBy mouth
YAMAA-01MDV.1YAMAA-01-002TREATMENT1IG.CM1IT.CM.CMSTDTC2023-09
YAMAA-01MDV.1YAMAA-01-002TREATMENT1IG.CM1IT.CM.CMPRIORY
YAMAA-01MDV.1YAMAA-01-002TREATMENT1IG.CM1IT.CM.CMONGOY
YAMAA-01MDV.1YAMAA-01-002TREATMENT1IG.CM2IT.CM.CMTRTIBUPROFEN
YAMAA-01MDV.1YAMAA-01-002TREATMENT1IG.CM2IT.CM.CMINDCBack pain
YAMAA-01MDV.1YAMAA-01-002TREATMENT1IG.CM2IT.CM.CMDSTXT200-400
YAMAA-01MDV.1YAMAA-01-002TREATMENT1IG.CM2IT.CM.CMDOSUmg
YAMAA-01MDV.1YAMAA-01-002TREATMENT1IG.CM2IT.CM.CMDOSFRQTwice daily
YAMAA-01MDV.1YAMAA-01-002TREATMENT1IG.CM2IT.CM.CMROUTEBy mouth
YAMAA-01MDV.1YAMAA-01-002TREATMENT1IG.CM2IT.CM.CMSTDTC2024-04-02
YAMAA-01MDV.1YAMAA-01-002TREATMENT1IG.CM2IT.CM.CMENDTC2024-04-09
YAMAA-01MDV.1YAMAA-01-002TREATMENT1IG.CM2IT.CM.CMPRIORN
YAMAA-01MDV.1YAMAA-01-002TREATMENT1IG.CM2IT.CM.CMONGON

Expected output

Under review
3 expected rows

expected/cm.csv

Edit
3 rows
expected/cm.csv
DOMAINSTUDYIDUSUBJIDCMSEQCMTRTCMINDCCMDOSECMDOSTXTCMDOSUCMDOSFRQCMROUTECMSTDTCCMENDTCCMSTRTPTCMSTTPTCMENRTPTCMENTPT
CMYAMAA-011ASPIRINHeadache100—mgQDORAL2024-03-052024-03-12————
CMYAMAA-011LISINOPRILHypertension10—mgQDORAL2023-09—BEFORESCREENINGONGOINGEND OF STUDY
CMYAMAA-012IBUPROFENBack pain—200-400mgBIDORAL2024-04-022024-04-09————
Shaded columns are derived— = missing value

Comments and assessment materials

Comments

Signed in with GitHub; saved in repository Discussions

Mapping spec

Generated from the benchmark YAML; do not edit by hand

Variable NameVariable LabelTypeLengthControlled Terms or FormatOriginCoreConversion DefinitionVariable TypeVariable OrderComments for Define
DOMAINDomain AbbreviationCharAssignedSet constant value "CM".SDTM1
STUDYIDStudy IdentifierCharCollectedCopy value from ODM.StudyOID.SDTM2
USUBJIDUnique Subject IdentifierCharCollectedCopy value from ODM.SubjectKey.SDTM3
CMSEQSequence NumberNumCollectedCopy value from ODM.ItemGroupRepeatKey.SDTM4
CMTRTReported Name of Drug, Med, or TherapyCharDerivedSet per constructed row; see the Row construction sheet.SDTM5
CMINDCIndicationCharDerivedSet per constructed row; see the Row construction sheet.SDTM6
CMDOSEDose per AdministrationNumDerivedExtract the whole match matching ^[0-9]+(\.[0-9]+)?$ from DSTXT; a missing source → blank; no match → blank.SDTM7
CMDOSTXTDose DescriptionCharDerivedIf DSTXT IS NOT NULL AND CMDOSE IS NULL then "DSTXT"; otherwise blank.SDTM8
CMDOSUDose UnitsCharmgDerivedSet per constructed row; see the Row construction sheet.SDTM9
CMDOSFRQDosing Frequency per IntervalCharDerivedRecode FRQLBL: "Once daily" → "QD", "Twice daily" → "BID"; missing values stay missing; unlisted values are errors.SDTM10
CMROUTERoute of AdministrationCharDerivedRecode ROUTELBL: "By mouth" → "ORAL"; missing values stay missing; unlisted values are errors.SDTM11
CMSTDTCStart Date/Time of MedicationCharDerivedSet per constructed row; see the Row construction sheet.SDTM12
CMENDTCEnd Date/Time of MedicationCharDerivedSet per constructed row; see the Row construction sheet.SDTM13
CMSTRTPTStart Relative to Reference Time PointCharDerivedIf PRIOR = 'Y' then "BEFORE"; otherwise blank.SDTM14
CMSTTPTStart Reference Time PointCharDerivedIf CMSTRTPT IS NOT NULL then "SCREENING"; otherwise blank.SDTM15
CMENRTPTEnd Relative to Reference Time PointCharDerivedIf ONGO = 'Y' then "ONGOING"; otherwise blank.SDTM16
CMENTPTEnd Reference Time PointCharDerivedIf CMENRTPT IS NOT NULL then "END OF STUDY"; otherwise blank.SDTM17
TemplateInclude whenCMTRTCMINDCDSTXTCMDOSUFRQLBLROUTELBLCMSTDTCCMENDTCPRIORONGO
medicationAggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.CM.CMTRT'Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.CM.CMINDC'Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.CM.CMDSTXT'Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.CM.CMDOSU'Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.CM.CMDOSFRQ'Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.CM.CMROUTE'Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.CM.CMSTDTC'Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.CM.CMENDTC'Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.CM.CMPRIOR'Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.CM.CMONGO'
VariablePermitted values
CMDOSUmg
VersionDateAuthorDescriptionReviewerSign-off
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/sdtm-cm-collected-medications/full.md

Edit
28 lines

Following CDISC SDTM standards, use the provided ODM dataset to create a CM dataset with one record per collected medication.

The output dataset should contain the following columns in this order: DOMAIN, STUDYID, USUBJID, CMSEQ, CMTRT, CMINDC, CMDOSE, CMDOSTXT, CMDOSU, CMDOSFRQ, CMROUTE, CMSTDTC, CMENDTC, CMSTRTPT, CMSTTPT, CMENRTPT, CMENTPT

STUDYID is the ODM StudyOID and USUBJID is the SubjectKey, each as given.

CMSEQ is the medication repeat number within the subject. CMTRT and CMINDC keep the reported name and indication exactly as written. CMDOSE holds the collected dose when it is a plain number, and has no value otherwise. CMDOSTXT holds the collected dose when it is not a plain number, such as a range like 50-75, and has no value when CMDOSE carries the dose. CMDOSU is the unit of the collected dose. CMDOSFRQ maps the collected frequency label to controlled terminology: Once daily becomes QD and Twice daily becomes BID. CMROUTE maps the collected route label: By mouth becomes ORAL. CMSTDTC keeps the start as collected, with a partial date at its collected precision. CMENDTC keeps the end as collected, and has no value when no end date was collected. CMSTRTPT is BEFORE with CMSTTPT SCREENING when the taken-before-study box is checked, and both have no value otherwise. CMENRTPT is ONGOING with CMENTPT END OF STUDY when the ongoing box is checked, and both have no value otherwise. An ongoing medication has no end date.

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

prompts/sdtm-cm-collected-medications/conventions.md

Edit
14 lines

Following CDISC SDTM standards, use the provided ODM dataset to create a CM dataset with one record per collected medication.

The output dataset should contain the following columns in this order: DOMAIN, STUDYID, USUBJID, CMSEQ, CMTRT, CMINDC, CMDOSE, CMDOSTXT, CMDOSU, CMDOSFRQ, CMROUTE, CMSTDTC, CMENDTC, CMSTRTPT, CMSTTPT, CMENRTPT, CMENTPT

CMDOSFRQ and CMROUTE map the collected labels to controlled terminology. CMSTRTPT is BEFORE with CMSTTPT SCREENING, or both have no value. CMENRTPT is ONGOING with CMENTPT END OF STUDY, or both have no value.

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

prompts/sdtm-cm-collected-medications/brief.md

Edit
10 lines

Following CDISC SDTM standards, use the provided ODM dataset to create a CM dataset with one record per collected medication.

The output dataset should contain the following columns in this order: DOMAIN, STUDYID, USUBJID, CMSEQ, CMTRT, CMINDC, CMDOSE, CMDOSTXT, CMDOSU, CMDOSFRQ, CMROUTE, CMSTDTC, CMENDTC, CMSTRTPT, CMSTTPT, CMENRTPT, CMENTPT

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

yamaa code

Runs the yamaa specification; its result must match the expected output

run.R

Edit
4 lines
library(yamaa)cm <- yamaa_domain("spec.yaml")$outputcm

run.py

Edit
4 lines
import yamaacm = yamaa.yamaa_domain("spec.yaml").outputcm

Solution without yamaa

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

solutions/sdtm-cm-collected-medications/result.R

Edit
76 lines
# Reference solution for the yamaa benchmark sdtm-cm-collected-medications (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)library(stringr)odm <- read_csv(  "/app/input/odm.csv",  col_types = cols(.default = col_character()))# A plain number carries the dose; anything else (like a range 50-75) stays# as text. Frequency and route labels map to controlled terminology.cm <- odm |>  filter(ItemGroupOID == "IG.CM") |>  pivot_wider(    id_cols = c(StudyOID, SubjectKey, ItemGroupRepeatKey),    names_from = ItemOID,    values_from = Value,    values_fn = first  ) |>  mutate(    CMSEQ = as.integer(ItemGroupRepeatKey),    DOSE_RAW = str_trim(`IT.CM.CMDSTXT`),    DOSE_PLAIN = str_detect(DOSE_RAW, "^\\d+(\\.\\d+)?$"),    # BEFORE/SCREENING when the taken-before-study box is checked; ONGOING/    # END OF STUDY when the ongoing box is checked. An ongoing medication    # has no end date.    DOMAIN = "CM",    STUDYID = StudyOID,    USUBJID = SubjectKey,    CMTRT = na_if(`IT.CM.CMTRT`, ""),    CMINDC = na_if(`IT.CM.CMINDC`, ""),    CMDOSE = if_else(      DOSE_PLAIN, suppressWarnings(as.numeric(DOSE_RAW)), NA_real_,      missing = NA_real_    ),    CMDOSTXT = if_else(      DOSE_PLAIN, NA_character_, na_if(DOSE_RAW, ""), missing = na_if(DOSE_RAW, "")    ),    CMDOSU = na_if(`IT.CM.CMDOSU`, ""),    CMDOSFRQ = case_when(      `IT.CM.CMDOSFRQ` == "Once daily" ~ "QD",      `IT.CM.CMDOSFRQ` == "Twice daily" ~ "BID",      .default = na_if(`IT.CM.CMDOSFRQ`, "")    ),    CMROUTE = case_when(      `IT.CM.CMROUTE` == "By mouth" ~ "ORAL",      .default = na_if(`IT.CM.CMROUTE`, "")    ),    CMSTDTC = na_if(`IT.CM.CMSTDTC`, ""),    CMENDTC = if_else(      `IT.CM.CMONGO` == "Y", NA_character_, na_if(`IT.CM.CMENDTC`, ""),      missing = na_if(`IT.CM.CMENDTC`, "")    ),    CMSTRTPT = if_else(`IT.CM.CMPRIOR` == "Y", "BEFORE", NA_character_, missing = NA_character_),    CMSTTPT = if_else(`IT.CM.CMPRIOR` == "Y", "SCREENING", NA_character_, missing = NA_character_),    CMENRTPT = if_else(`IT.CM.CMONGO` == "Y", "ONGOING", NA_character_, missing = NA_character_),    CMENTPT = if_else(      `IT.CM.CMONGO` == "Y", "END OF STUDY", NA_character_, missing = NA_character_    )  ) |>  arrange(USUBJID, CMSEQ) |>  select(    DOMAIN, STUDYID, USUBJID, CMSEQ, CMTRT, CMINDC, CMDOSE, CMDOSTXT,    CMDOSU, CMDOSFRQ, CMROUTE, CMSTDTC, CMENDTC, CMSTRTPT, CMSTTPT,    CMENRTPT, CMENTPT  )dir.create("/app/output", showWarnings = FALSE)write_csv(cm, "/app/output/cm.csv", na = "")

solutions/sdtm-cm-collected-medications/result.py

Edit
92 lines
# Reference solution for the yamaa benchmark sdtm-cm-collected-medications (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 refrom pathlib import Pathimport polars as plodm = pl.read_csv("/app/input/odm.csv", infer_schema=False)wide = odm.filter(pl.col("ItemGroupOID") == "IG.CM").pivot(    index=["StudyOID", "SubjectKey", "ItemGroupRepeatKey"],    on="ItemOID",    values="Value",    aggregate_function="first",)# A plain number carries the dose; anything else (like a range 50-75) stays# as text. Frequency and route labels map to controlled terminology.def is_plain_number(value: str | None) -> bool:    return value is not None and re.fullmatch(r"\d+(\.\d+)?", value.strip() or "") is not Nonerows = []for record in wide.to_dicts():    dose_raw = (record.get("IT.CM.CMDSTXT") or "").strip() or None    if dose_raw is not None and is_plain_number(dose_raw):        dose, dosetxt = float(dose_raw), None    else:        dose, dosetxt = None, dose_raw    freq_raw = record.get("IT.CM.CMDOSFRQ")    freq = {"Once daily": "QD", "Twice daily": "BID"}.get(freq_raw, freq_raw) or None    route_raw = record.get("IT.CM.CMROUTE")    route = {"By mouth": "ORAL"}.get(route_raw, route_raw) or None    prior = record.get("IT.CM.CMPRIOR")    ongo = record.get("IT.CM.CMONGO")    # BEFORE/SCREENING when the taken-before-study box is checked; ONGOING/    # END OF STUDY when the ongoing box is checked. An ongoing medication    # has no end date.    endtc = record.get("IT.CM.CMENDTC") or None    if ongo == "Y":        endtc = None    rows.append(        {            "DOMAIN": "CM",            "STUDYID": record["StudyOID"],            "USUBJID": record["SubjectKey"],            "CMSEQ": int(record["ItemGroupRepeatKey"]),            "CMTRT": record.get("IT.CM.CMTRT") or None,            "CMINDC": record.get("IT.CM.CMINDC") or None,            "CMDOSE": dose,            "CMDOSTXT": dosetxt,            "CMDOSU": record.get("IT.CM.CMDOSU") or None,            "CMDOSFRQ": freq,            "CMROUTE": route,            "CMSTDTC": record.get("IT.CM.CMSTDTC") or None,            "CMENDTC": endtc,            "CMSTRTPT": "BEFORE" if prior == "Y" else None,            "CMSTTPT": "SCREENING" if prior == "Y" else None,            "CMENRTPT": "ONGOING" if ongo == "Y" else None,            "CMENTPT": "END OF STUDY" if ongo == "Y" else None,        }    )cm = pl.DataFrame(    rows,    schema={        "DOMAIN": pl.String,        "STUDYID": pl.String,        "USUBJID": pl.String,        "CMSEQ": pl.Int64,        "CMTRT": pl.String,        "CMINDC": pl.String,        "CMDOSE": pl.Float64,        "CMDOSTXT": pl.String,        "CMDOSU": pl.String,        "CMDOSFRQ": pl.String,        "CMROUTE": pl.String,        "CMSTDTC": pl.String,        "CMENDTC": pl.String,        "CMSTRTPT": pl.String,        "CMSTTPT": pl.String,        "CMENRTPT": pl.String,        "CMENTPT": pl.String,    },).sort(["USUBJID", "CMSEQ"])Path("/app/output").mkdir(exist_ok=True)cm.write_csv("/app/output/cm.csv")

solutions/sdtm-cm-collected-medications/result.sas

Edit
42 lines
/* opensas reference solution for the yamaa benchmark sdtm-cm-collected-medications.   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 ItemGroupRepeatKey; run;data wide;  length CMTRT CMINDC CMDOSU CMDOSFRQ CMROUTE CMSTDTC CMENDTC CMPRIOR CMONGO DOSETEXT $1024;  retain CMTRT CMINDC CMDOSU CMDOSFRQ CMROUTE CMSTDTC CMENDTC CMPRIOR CMONGO DOSETEXT;  set ordered;  where ItemGroupOID='IG.CM';  by StudyOID SubjectKey ItemGroupRepeatKey;  if first.ItemGroupRepeatKey then do;    CMTRT=''; CMINDC=''; CMDOSU=''; CMDOSFRQ=''; CMROUTE=''; CMSTDTC=''; CMENDTC=''; CMPRIOR=''; CMONGO=''; DOSETEXT='';  end;    if ItemOID='IT.CM.CMTRT' then CMTRT=Value;  if ItemOID='IT.CM.CMINDC' then CMINDC=Value;  if ItemOID='IT.CM.CMDOSU' then CMDOSU=Value;  if ItemOID='IT.CM.CMDOSFRQ' then CMDOSFRQ=Value;  if ItemOID='IT.CM.CMROUTE' then CMROUTE=Value;  if ItemOID='IT.CM.CMSTDTC' then CMSTDTC=Value;  if ItemOID='IT.CM.CMENDTC' then CMENDTC=Value;  if ItemOID='IT.CM.CMPRIOR' then CMPRIOR=Value;  if ItemOID='IT.CM.CMONGO' then CMONGO=Value;  if ItemOID='IT.CM.CMDSTXT' then DOSETEXT=Value;  if last.ItemGroupRepeatKey then output;run;data result; set wide; length DOMAIN $2 STUDYID USUBJID CMDOSTXT CMSTRTPT CMSTTPT CMENRTPT CMENTPT $1024;DOMAIN='CM'; STUDYID=StudyOID; USUBJID=SubjectKey; CMSEQ=input(ItemGroupRepeatKey,best32.);if prxmatch('/^[+-]?[0-9]+(\.[0-9]+)?$/',strip(DOSETEXT)) then CMDOSE=input(DOSETEXT,best32.); else CMDOSTXT=DOSETEXT;if CMDOSFRQ='Once daily' then CMDOSFRQ='QD'; if CMDOSFRQ='Twice daily' then CMDOSFRQ='BID'; if CMROUTE='By mouth' then CMROUTE='ORAL';if CMPRIOR='Y' then do; CMSTRTPT='BEFORE'; CMSTTPT='SCREENING'; end;if CMONGO='Y' then do; CMENDTC=''; CMENRTPT='ONGOING'; CMENTPT='END OF STUDY'; end; run;proc sql;  create table final as select DOMAIN, STUDYID, USUBJID, CMSEQ, CMTRT, CMINDC, CMDOSE, CMDOSTXT, CMDOSU, CMDOSFRQ, CMROUTE, CMSTDTC, CMENDTC, CMSTRTPT, CMSTTPT, CMENRTPT, CMENTPT from result;quit;proc export data=final outfile="/app/output/cm.csv" dbms=csv replace; run;