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: one row per adverse event (AE), marking treatment
emergence (TRTEMFL) and the subject's earliest treatment-emergent
event (AOCCFL) from onset, first exposure, and the study's
post-last-exposure emergence window: 30 days for a non-serious event,
90 days for a serious one.
Input: adverse event records carrying the reported term
(AETERM), whether the event was serious (AESER, Y or N, empty
when not recorded) and the collected onset moment (ASTDTM, empty
when never collected), plus, from the subject-level analysis dataset
(ADSL), the moments of first and last exposure (TRTSDTM, TRTEDTM)
and the end-of-treatment status (EOTSTT: COMPLETED,
DISCONTINUED or ONGOING). While treatment is ongoing, TRTEDTM
holds the last exposure so far. An untreated subject appears in ADSL
with an empty TRTSDTM and none of their events get flagged.
Variables:
TEENDDTMis the end of the treatment-emergent window: 30 days after last exposure for an event recorded as non-serious, and 90 days after for any other event, serious or with its seriousness not recorded. It stays empty while treatment is ongoing, because the window has no end yet, and for an untreated subject.TRTEMFLholdsYwhen the event started inside the window - at or after first exposure and at or before the window end, or at any time after first exposure while treatment is ongoing. It stays empty for an earlier or later event. A missing onset cannot be ruled pre-treatment, so the conservative convention flags itYwhenever the subject was treated; an untreated subject's events stay empty.AOCCFLholdsYon the subject's earliest treatment-emergent event, ordered by onset moment with the lower sequence number (AESEQ) settling ties at the same second. All other rows stay empty; a treatment-emergent event with a missing onset is flagged but cannot be ordered, so it never carries the occurrence flag.
Note: emergence is decided at the moment, not the day: an event that started earlier on the day of first exposure and one that started later that same day fall on opposite sides, and a start date alone cannot tell them apart. Both window ends belong to the window, and a day is 24 hours, so a serious event one second past 90 days after last exposure is outside it.
Note: a collected datetime without seconds is coerced to the
second (seconds zero-filled) and compared at second precision.
HEADACHE is collected as 2025-03-04T11:45 and VOMITING as
2025-03-04T11:45:00; both land on the same second, so the
AOCCFL tie-break ("the lower sequence number settles ties at
the same second") is what picks the earliest treatment-emergent
event. No time-imputation flag is derived for the coerced value:
the onset is read directly as a date and time, which takes the
omitted seconds as collected zeros rather than as supplied ones.
Inputs
Under review2 source filesinput/adsl.csv
Edit4 rows| STUDYID | USUBJID | TRTSDTM | TRTEDTM | EOTSTT |
|---|---|---|---|---|
| PILOT7 | 2025-03-04T09:00:00 | 2025-03-10T09:00:00 | COMPLETED | |
| PILOT7 | 2025-03-05T09:00:00 | 2025-03-05T09:00:00 | DISCONTINUED | |
| PILOT7 | — | — | — | |
| PILOT7 | 2025-03-06T08:00:00 | 2025-05-01T08:00:00 | ONGOING |
input/ae.csv
Edit15 rows| STUDYID | USUBJID | AESEQ | AETERM | AESER | AESTDTC |
|---|---|---|---|---|---|
| PILOT7 | 1 | CHILLS | N | 2025-03-04T07:15:00 | |
| PILOT7 | 2 | HEADACHE | N | 2025-03-04T11:45 | |
| PILOT7 | 3 | NAUSEA | N | 2025-03-06T22:30:00 | |
| PILOT7 | 4 | VOMITING | N | 2025-03-04T11:45:00 | |
| PILOT7 | 5 | BACK PAIN | N | 2025-04-15T10:00:00 | |
| PILOT7 | 6 | COUGH | N | 2025-03-20T08:00:00 | |
| PILOT7 | 7 | PNEUMONIA | Y | 2025-05-20T14:00:00 | |
| PILOT7 | 8 | ARTHRALGIA | — | 2025-04-20T10:00:00 | |
| PILOT7 | 1 | RASH | N | 2025-03-05T09:00:00 | |
| PILOT7 | 2 | PRURITUS | N | — | |
| PILOT7 | 3 | DIZZINESS | N | 2025-04-04T09:00 | |
| PILOT7 | 4 | SYNCOPE | Y | 2025-06-03T09:00:01 | |
| PILOT7 | 1 | FATIGUE | N | 2025-03-07T13:05:00 | |
| PILOT7 | 1 | INSOMNIA | N | 2025-03-05T22:00:00 | |
| PILOT7 | 2 | ALOPECIA | N | 2025-08-12T10:00:00 |
Expected output
Under review15 expected rowsexpected/adae.csv
Edit15 rows| STUDYID | USUBJID | AESEQ | AETERM | AESER | ASTDTM | TRTSDTM | TRTEDTM | EOTSTT | TEENDDTM | TRTEMFL | AOCCFL |
|---|---|---|---|---|---|---|---|---|---|---|---|
| PILOT7 | 1 | CHILLS | N | 2025-03-04T07:15:00 | 2025-03-04T09:00:00 | 2025-03-10T09:00:00 | COMPLETED | 2025-04-09T09:00:00 | — | — | |
| PILOT7 | 2 | HEADACHE | N | 2025-03-04T11:45:00 | 2025-03-04T09:00:00 | 2025-03-10T09:00:00 | COMPLETED | 2025-04-09T09:00:00 | Y | Y | |
| PILOT7 | 3 | NAUSEA | N | 2025-03-06T22:30:00 | 2025-03-04T09:00:00 | 2025-03-10T09:00:00 | COMPLETED | 2025-04-09T09:00:00 | Y | — | |
| PILOT7 | 4 | VOMITING | N | 2025-03-04T11:45:00 | 2025-03-04T09:00:00 | 2025-03-10T09:00:00 | COMPLETED | 2025-04-09T09:00:00 | Y | — | |
| PILOT7 | 5 | BACK PAIN | N | 2025-04-15T10:00:00 | 2025-03-04T09:00:00 | 2025-03-10T09:00:00 | COMPLETED | 2025-04-09T09:00:00 | — | — | |
| PILOT7 | 6 | COUGH | N | 2025-03-20T08:00:00 | 2025-03-04T09:00:00 | 2025-03-10T09:00:00 | COMPLETED | 2025-04-09T09:00:00 | Y | — | |
| PILOT7 | 7 | PNEUMONIA | Y | 2025-05-20T14:00:00 | 2025-03-04T09:00:00 | 2025-03-10T09:00:00 | COMPLETED | 2025-06-08T09:00:00 | Y | — | |
| PILOT7 | 8 | ARTHRALGIA | — | 2025-04-20T10:00:00 | 2025-03-04T09:00:00 | 2025-03-10T09:00:00 | COMPLETED | 2025-06-08T09:00:00 | Y | — | |
| PILOT7 | 1 | RASH | N | 2025-03-05T09:00:00 | 2025-03-05T09:00:00 | 2025-03-05T09:00:00 | DISCONTINUED | 2025-04-04T09:00:00 | Y | Y | |
| PILOT7 | 2 | PRURITUS | N | — | 2025-03-05T09:00:00 | 2025-03-05T09:00:00 | DISCONTINUED | 2025-04-04T09:00:00 | Y | — | |
| PILOT7 | 3 | DIZZINESS | N | 2025-04-04T09:00:00 | 2025-03-05T09:00:00 | 2025-03-05T09:00:00 | DISCONTINUED | 2025-04-04T09:00:00 | Y | — | |
| PILOT7 | 4 | SYNCOPE | Y | 2025-06-03T09:00:01 | 2025-03-05T09:00:00 | 2025-03-05T09:00:00 | DISCONTINUED | 2025-06-03T09:00:00 | — | — | |
| PILOT7 | 1 | FATIGUE | N | 2025-03-07T13:05:00 | — | — | — | — | — | — | |
| PILOT7 | 1 | INSOMNIA | N | 2025-03-05T22:00:00 | 2025-03-06T08:00:00 | 2025-05-01T08:00:00 | ONGOING | — | — | — | |
| PILOT7 | 2 | ALOPECIA | N | 2025-08-12T10:00:00 | 2025-03-06T08:00:00 | 2025-05-01T08:00:00 | ONGOING | — | Y | Y |
Human review and assessment
| Dataset Name | Variable Name | Variable Label | Type | Codelist/Controlled Terms | Core | Computational Method | Origin |
|---|---|---|---|---|---|---|---|
| ADAE | STUDYID | Study Identifier | character | Copy value from AE.STUDYID. | Predecessor | ||
| ADAE | USUBJID | Unique Subject Identifier | character | Copy value from AE.USUBJID. | Predecessor | ||
| ADAE | AESEQ | Sequence Number | numeric | Copy value from AE.AESEQ. | Predecessor | ||
| ADAE | AETERM | Reported Term for the Adverse Event | character | Copy value from AE.AETERM. | Predecessor | ||
| ADAE | AESER | Serious Event | character | Copy value from AE.AESER. | Predecessor | ||
| ADAE | ASTDTM | Analysis Start Date/Time | numeric | ISO 8601 | Copy value from AE.AESTDTC. | Predecessor | |
| ADAE | TRTSDTM | Datetime of First Exposure to Treatment | numeric | ISO 8601 | Copy value from ADSL.TRTSDTM. | Predecessor | |
| ADAE | TRTEDTM | Datetime of Last Exposure to Treatment | numeric | ISO 8601 | Copy value from ADSL.TRTEDTM. | Predecessor | |
| ADAE | EOTSTT | End of Treatment Status | character | Copy value from ADSL.EOTSTT. | Predecessor | ||
| ADAE | TEENDDTM | End of Treatment-Emergent Window | numeric | ISO 8601 | If EOTSTT = 'ONGOING' then "None"; If AESER = 'N' then the datetime 30 days after TRTEDTM; otherwise the datetime 90 days after TRTEDTM. | Derived | |
| ADAE | TRTEMFL | Treatment Emergent Analysis Flag | character | Y | If TRTSDTM IS NULL then "None"; If ASTDTM IS NULL then "Y"; If ASTDTM >= TRTSDTM AND (EOTSTT = 'ONGOING' OR ASTDTM <= TEENDDTM) then "Y"; otherwise "None". | Derived | |
| ADAE | AOCCFL | First Occurrence Within Subject Flag | character | Y | "Y" when AOCCSEQ = 1; blank otherwise. | Derived |
| Variable | Permitted values |
|---|---|
| TRTEMFL | Y |
| AOCCFL | Y |
| Version | Date | Author | Description | Reviewer | Sign-off |
|---|---|---|---|---|---|
| 1.7 | 2026-10-20 | yamaa docs build | Read a specification in the 1.0 surface as its 0.5 counterpart; state that missing values stay missing where a mapping declares no missing handler, and leave out a declared missing answer that restates a handler's default | ||
| 1.6 | 2026-10-17 | yamaa docs build | Describe collected date parts written as ISO 8601 date text and times of day counted in seconds since midnight | ||
| 1.5 | 2026-10-17 | yamaa docs build | Name collected precision in words instead of letter codes; state imputation fallbacks, minimum source precision, bounds ignored outside the collected period, and invalid text with no handler as an error; describe date and datetime shifts, imputation flag codes, and partial text giving no date part | ||
| 1.4 | 2026-10-15 | yamaa docs build | State datetime precision codes through the hour and minute, and complete only the time parts a collected datetime lacks | ||
| 1.3 | 2026-09-29 | yamaa docs build | Show study codelist names, external dictionaries, and ISO 8601 formats in variable rows; list the document's codelist values and metadata | ||
| 1.2 | 2026-09-29 | yamaa docs build | Classify ADaM copies from a declared input as Predecessor and recodes as Derived, and SDTM recodes of locally derived columns as Derived | ||
| 1.1 | 2026-09-29 | yamaa docs build | Resolve lookups into the donor record they select, and give every derivation shape a plain-language rule instead of its raw YAML | ||
| 1.0 | yamaa docs build | Initial generation from spec.yaml |
prompts/adam-adae-onset-emergence/full.md
Edit28 linesFollowing CDISC ADaM standards, use the provided ADSL and AE datasets to create an ADAE dataset with one record per AE record, the events of an untreated subject included.
The output dataset should contain the following columns in this order: STUDYID, USUBJID, AESEQ, AETERM, AESER, ASTDTM, TRTSDTM, TRTEDTM, EOTSTT, TEENDDTM, TRTEMFL, AOCCFL
Treatment emergence is decided at the moment, to the second, not the day. A subject is untreated when TRTSDTM has no value.
- ASTDTM is the collected onset, AESTDTC, as a date and time to the second; an onset collected without seconds falls on second zero. ASTDTM has no value when AESTDTC is empty.
- TEENDDTM is the end of the treatment-emergent window: 30 days after TRTEDTM when AESER is "N", and 90 days after TRTEDTM for any other event, serious or with AESER not recorded. A day is 24 hours. TEENDDTM has no value when EOTSTT is "ONGOING", and for an untreated subject.
- TRTEMFL is "Y" when ASTDTM is at or after TRTSDTM and at or before TEENDDTM. When EOTSTT is "ONGOING", TRTEMFL is "Y" for any ASTDTM at or after TRTSDTM. TRTEMFL is also "Y" for an event with no ASTDTM when the subject was treated. TRTEMFL has no value otherwise, and for every event of an untreated subject.
- AOCCFL is "Y" on the subject's earliest treatment-emergent event by ASTDTM, the lower AESEQ settling a tie at the same second. AOCCFL has no value on every other record, a treatment-emergent event with no ASTDTM included.
Read the source datasets from /app/input and save the completed dataset as /app/output/adae.csv.
prompts/adam-adae-onset-emergence/conventions.md
Edit14 linesFollowing CDISC ADaM standards, use the provided ADSL and AE datasets to create an ADAE dataset with one record per AE record, the events of an untreated subject included.
The output dataset should contain the following columns in this order: STUDYID, USUBJID, AESEQ, AETERM, AESER, ASTDTM, TRTSDTM, TRTEDTM, EOTSTT, TEENDDTM, TRTEMFL, AOCCFL
ASTDTM is a date and time to the second, or has no value. TEENDDTM is a date and time or has no value, and a day is 24 hours. TRTEMFL is "Y" or has no value. AOCCFL is "Y" or has no value.
Read the source datasets from /app/input and save the completed dataset as /app/output/adae.csv.
prompts/adam-adae-onset-emergence/brief.md
Edit10 linesFollowing CDISC ADaM standards, use the provided ADSL and AE datasets to create an ADAE dataset with one record per AE record, the events of an untreated subject included.
The output dataset should contain the following columns in this order: STUDYID, USUBJID, AESEQ, AETERM, AESER, ASTDTM, TRTSDTM, TRTEDTM, EOTSTT, TEENDDTM, TRTEMFL, AOCCFL
Read the source datasets from /app/input and save the completed dataset as /app/output/adae.csv.
R
Edit3 lineslibrary(yamaa)yamaa_spec("spec.yaml")$run()$outputPython
Edit3 linesimport yamaayamaa.spec("spec.yaml").run().outputsolutions/adam-adae-onset-emergence/result.R
Edit96 lines# Reference solution for the yamaa benchmark adam-adae-onset-emergence (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.# ADAE: treatment emergence decided at the second, one record per AE record.suppressPackageStartupMessages({ library(dplyr) library(readr) library(stringr)})in_dir <- "/app/input"out_dir <- "/app/output"dir.create(out_dir, showWarnings = FALSE, recursive = TRUE)read_chr <- function(path) { read_csv(path, col_types = cols(.default = col_character()), na = c(""), trim_ws = TRUE, progress = FALSE)}adsl <- read_chr(file.path(in_dir, "adsl.csv"))ae <- read_chr(file.path(in_dir, "ae.csv"))# ISO 8601 datetime text to POSIXct (UTC, so a day is always 24 hours).# A value without seconds falls on second zero; anything else is no value.parse_dtm <- function(x) { x <- str_trim(x) full <- case_when( is.na(x) ~ NA_character_, str_detect(x, "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$") ~ x, str_detect(x, "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}$") ~ paste0(x, ":00"), TRUE ~ NA_character_ ) as.POSIXct(full, format = "%Y-%m-%dT%H:%M:%S", tz = "UTC")}fmt_dtm <- function(x) { out <- format(x, "%Y-%m-%dT%H:%M:%S", tz = "UTC") out[is.na(x)] <- NA_character_ out}day_secs <- 24 * 60 * 60adsl_t <- adsl %>% transmute( STUDYID, USUBJID, EOTSTT, TRTSDTM = parse_dtm(TRTSDTM), TRTEDTM = parse_dtm(TRTEDTM) )adae <- ae %>% mutate(AESEQ = as.integer(AESEQ), .row = row_number()) %>% left_join(adsl_t, by = c("STUDYID", "USUBJID")) %>% mutate( ASTDTM = parse_dtm(AESTDTC), treated = !is.na(TRTSDTM), ongoing = !is.na(EOTSTT) & EOTSTT == "ONGOING", window_days = if_else(!is.na(AESER) & AESER == "N", 30, 90), TEENDDTM = if_else(treated & !ongoing, TRTEDTM + window_days * day_secs, as.POSIXct(NA, tz = "UTC")), TRTEMFL = case_when( !treated ~ NA_character_, is.na(ASTDTM) ~ "Y", ongoing & ASTDTM >= TRTSDTM ~ "Y", !ongoing & !is.na(TEENDDTM) & ASTDTM >= TRTSDTM & ASTDTM <= TEENDDTM ~ "Y", TRUE ~ NA_character_ ) )# AOCCFL: earliest treatment-emergent event with an ASTDTM, lower AESEQ on ties.first_te <- adae %>% filter(TRTEMFL == "Y", !is.na(ASTDTM)) %>% arrange(USUBJID, ASTDTM, AESEQ) %>% group_by(USUBJID) %>% slice(1) %>% ungroup() %>% select(.row)adae <- adae %>% mutate(AOCCFL = if_else(.row %in% first_te$.row, "Y", NA_character_)) %>% arrange(.row) %>% transmute( STUDYID, USUBJID, AESEQ, AETERM, AESER, ASTDTM = fmt_dtm(ASTDTM), TRTSDTM = fmt_dtm(TRTSDTM), TRTEDTM = fmt_dtm(TRTEDTM), EOTSTT, TEENDDTM = fmt_dtm(TEENDDTM), TRTEMFL, AOCCFL )write_csv(adae, file.path(out_dir, "adae.csv"), na = "")solutions/adam-adae-onset-emergence/result.py
Edit126 lines# Reference solution for the yamaa benchmark adam-adae-onset-emergence (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."""Derive ADAE (one record per AE record) from ADSL and AE.Treatment emergence is judged to the second."""import csvfrom datetime import datetime, timedeltafrom pathlib import PathINPUT = Path("/app/input")OUTPUT = Path("/app/output")COLUMNS = [ "STUDYID", "USUBJID", "AESEQ", "AETERM", "AESER", "ASTDTM", "TRTSDTM", "TRTEDTM", "EOTSTT", "TEENDDTM", "TRTEMFL", "AOCCFL",]ISO = "%Y-%m-%dT%H:%M:%S"def parse_dtm(value): """ISO 8601 date-time to the second; a value without seconds is at second zero.""" value = (value or "").strip() if not value: return None for fmt in (ISO, "%Y-%m-%dT%H:%M"): try: return datetime.strptime(value, fmt) except ValueError: pass return Nonedef fmt_dtm(value): return value.strftime(ISO) if value is not None else ""def read_csv(path): with open(path, newline="", encoding="utf-8") as handle: return list(csv.DictReader(handle))def main(): adsl = { (row["STUDYID"], row["USUBJID"]): row for row in read_csv(INPUT / "adsl.csv") } ae = read_csv(INPUT / "ae.csv") records = [] for row in ae: subject = adsl.get((row["STUDYID"], row["USUBJID"]), {}) trtsdtm = parse_dtm(subject.get("TRTSDTM")) trtedtm = parse_dtm(subject.get("TRTEDTM")) eotstt = (subject.get("EOTSTT") or "").strip() aeser = (row.get("AESER") or "").strip() astdtm = parse_dtm(row.get("AESTDTC")) treated = trtsdtm is not None ongoing = eotstt == "ONGOING" teenddtm = None if treated and not ongoing and trtedtm is not None: days = 30 if aeser == "N" else 90 teenddtm = trtedtm + timedelta(days=days) trtemfl = "" if treated: if astdtm is None: trtemfl = "Y" elif astdtm >= trtsdtm: if ongoing: trtemfl = "Y" elif teenddtm is not None and astdtm <= teenddtm: trtemfl = "Y" records.append({ "STUDYID": row["STUDYID"], "USUBJID": row["USUBJID"], "AESEQ": int(row["AESEQ"]), "AETERM": row["AETERM"], "AESER": aeser, "ASTDTM": astdtm, "TRTSDTM": trtsdtm, "TRTEDTM": trtedtm, "EOTSTT": eotstt, "TEENDDTM": teenddtm, "TRTEMFL": trtemfl, "AOCCFL": "", }) records.sort(key=lambda r: (r["STUDYID"], r["USUBJID"], r["AESEQ"])) # First treatment-emergent event per subject by ASTDTM, lower AESEQ on ties. first = {} for rec in records: if rec["TRTEMFL"] != "Y" or rec["ASTDTM"] is None: continue key = (rec["STUDYID"], rec["USUBJID"]) best = first.get(key) if best is None or (rec["ASTDTM"], rec["AESEQ"]) < (best["ASTDTM"], best["AESEQ"]): first[key] = rec for rec in first.values(): rec["AOCCFL"] = "Y" OUTPUT.mkdir(parents=True, exist_ok=True) with open(OUTPUT / "adae.csv", "w", newline="", encoding="utf-8") as handle: writer = csv.writer(handle, lineterminator="\n") writer.writerow(COLUMNS) for rec in records: writer.writerow([ rec["STUDYID"], rec["USUBJID"], rec["AESEQ"], rec["AETERM"], rec["AESER"], fmt_dtm(rec["ASTDTM"]), fmt_dtm(rec["TRTSDTM"]), fmt_dtm(rec["TRTEDTM"]), rec["EOTSTT"], fmt_dtm(rec["TEENDDTM"]), rec["TRTEMFL"], rec["AOCCFL"], ])if __name__ == "__main__": main()solutions/adam-adae-onset-emergence/result.sas
Edit49 lines/* opensas reference solution for the yamaa benchmark adam-adae-onset-emergence. Reads the benchmark inputs and derives the requested output. Execute with the existing opensas runtime: opensas /app/output/result.sas. */data adsl; length STUDYID USUBJID TRTSDTM TRTEDTM EOTSTT $1024; infile "/app/input/adsl.csv" dsd dlm="," firstobs=2 truncover lrecl=32767; input STUDYID : $char1024. USUBJID : $char1024. TRTSDTM : $char1024. TRTEDTM : $char1024. EOTSTT : $char1024.;run;data ae; length STUDYID USUBJID AETERM AESER AESTDTC $1024; infile "/app/input/ae.csv" dsd dlm="," firstobs=2 truncover lrecl=32767; input STUDYID : $char1024. USUBJID : $char1024. AESEQ AETERM : $char1024. AESER : $char1024. AESTDTC : $char1024.;run;proc sql; create table joined as select a.*,b.TRTSDTM,b.TRTEDTM,b.EOTSTT from ae as a left join adsl as b on a.STUDYID=b.STUDYID and a.USUBJID=b.USUBJID; quit;data events; length ASTDTM TEENDDTM $19 TRTEMFL $1; set joined; ASTDTM=''; TEENDDTM=''; TRTEMFL=''; /* Datetimes collected without seconds are completed to the second so the onset and the first exposure compare at the moment, not the day. */ if not missing(AESTDTC) then ASTDTM=cats(AESTDTC,ifc(lengthn(AESTDTC)=16,':00','')); /* The window ends 30 days after last exposure for an event recorded as non-serious and 90 days after for any other; while treatment is ongoing it has no end. Whole days keep the time of day. */ window_days=90; if AESER='N' then window_days=30; if upcase(EOTSTT) ne 'ONGOING' and not missing(TRTEDTM) then TEENDDTM=cats(put(input(substr(TRTEDTM,1,10),yymmdd10.)+window_days,yymmdd10.),substr(TRTEDTM,11)); onset=input(ASTDTM,e8601dt.); treatment=input(TRTSDTM,e8601dt.); window_end=input(TEENDDTM,e8601dt.); /* The window rule: onset at or after first exposure and, unless treatment is ongoing, at or before the window end is treatment-emergent. A missing onset cannot be ruled pre-treatment, so a treated subject's event with a missing onset is flagged Y; an untreated subject (no first exposure) is never treatment-emergent. */ if not missing(treatment) then do; if missing(onset) then TRTEMFL='Y'; else if onset>=treatment and (upcase(EOTSTT)='ONGOING' or (not missing(window_end) and onset<=window_end)) then TRTEMFL='Y'; end;run;proc sort data=events(where=(TRTEMFL='Y' and not missing(onset))) out=eligible; by STUDYID USUBJID onset AESEQ; run;data firstevent; set eligible; by STUDYID USUBJID; if first.USUBJID; keep STUDYID USUBJID AESEQ; run;proc sql; create table result as select a.*,case when not missing(b.AESEQ) then 'Y' else '' end as AOCCFL from events as a left join firstevent as b on a.STUDYID=b.STUDYID and a.USUBJID=b.USUBJID and a.AESEQ=b.AESEQ; quit;proc sql; create table final as select STUDYID, USUBJID, AESEQ, AETERM, AESER, ASTDTM, TRTSDTM, TRTEDTM, EOTSTT, TEENDDTM, TRTEMFL, AOCCFL from result;quit;proc export data=final outfile="/app/output/adae.csv" dbms=csv replace; run;
yamaa