StatAgentWeekly email

Pseudocode from define.xml derivation text, tested on the data

Paste derivation comments from define.xml, get numbered pseudocode and Python; 10 of 14 columns matched the dataset.

About 30 minWordWorked example, recomputed

What you get

2
D7fxno
ABCDEF
1VariableRecords matching (as written)RecordsMatches all recordsRecords matching (SOC spelling fixed)Cause of mismatch
2ASTDT11911191yes1191
3ASTDTF11911191yes1191
4AENDT11911191yes1191
5ASTDY11911191yes1191
6AENDY11911191yes1191
7ADURN11871191no1187production program computes duration before imputing the start day; not stated in the define text
8ADURU11871191no1187same 4 records as ADURN
9TRTEMFL11911191yes1191
10AOCCFL11911191yes1191
11AOCCSFL11911191yes1191
12AOCCPFL11911191yes1191
13AOCC02FL11911191yes1191
14CQ01NAM10101191no1191SOC string in the define text has a stray space ('SUBC UTANEOUS')
15AOCC01FL11071191no1191knock-on of CQ01NAM
variable_matchShowing 14 of 14 rows

Swipe sideways to see every column.

Each derived column compared with adam_adae.xpt, record by record (1,191 records). Amber = does not match on every record.

Draft for review. Public data only.

Get the next workflow by email

The prompt

For each ADAE derivation comment below, write numbered pseudocode a programmer could implement without
the define: inputs, order of steps, handling of missing and partial values.
Then write Python (pandas) that implements it on sdtm_ae.xpt and adam_adsl.xpt, run it, and print counts.
If the text is ambiguous, contradictory or looks like a typo, say so and state your choice.
Do not invent rules the text does not give.

[paste the derivation comments and the input file notes here]

Works in any chat assistant that writes and runs code; not tested in Microsoft 365 Copilot

Sample input used here

ADAE derivation comments, adam_define.xml, CDISCPILOT01

TRTSDT (Date of First Exposure to Treatment): ADSL.TRTSDT
ASTDT (Analysis Start Date): AE.AESTDTC, converted to a numeric SAS date. Some events with partial dates are imputed in a conservative manner. If the day component is missing, a value of '01' is used. If both the month and day are
ASTDTF (Analysis Start Date Imputation Flag): ASTDTF='D' if the day value within the character date is imputed. Note that only day values needed to be imputed for this study.
AENDT (Analysis End Date): AE.AEENDTC, converted to a numeric SAS date
ASTDY (Analysis Start Relative Day): IF ASTDT>=TRTSDT>MISSING then ASTDY=ASTDT-TRTSDT+1 Else if TRTSDT>ASTDT>MISSING then ASTDY=ASTDT-TRTSDT
AENDY (Analysis End Relative Day): IF AENDT>=TRTSDT>MISSING then AENDY=AENDT-TRTSDT+1 Else if TRTSDT>AENDT>MISSING then AENDY=AENDT-TRTSDT
ADURN (AE Duration (N)): ADURN=AENDT-ASTDT+1
ADURU (AE Duration Units): If ADURN is not missing then ADURU='DAY'
TRTEMFL (Treatment Emergent Analysis Flag): If ASTDT >= TRTSDT > . then TRTEMFL='Y'. Otherwise TRTEMFL='N'
AOCCFL (1st Occurrence of Any AE Flag): Subset to TRTEMFL='Y' and sort by Subject (USUBJID), Start Date (ASTDT), and Sequence Number (AESEQ) and flag the first record (set AOCCFL='Y') within each Subject
AOCCSFL (1st Occurrence of SOC Flag): Subset to TRTEMFL='Y' and sort by Subject (USUBJID), System Organ Class (AEBODSYS), Start Date (ASTDT), and Sequence Number (AESEQ) and flag the first record (set AOCCSFL='Y') within each Subj
AOCCPFL (1st Occurrence of Preferred Term Flag): Subset to TRTEMFL='Y' and sort by Subject (USUBJID), System Organ Class (AEBODSYS), Preferred Term (AEDECOD), Start Date (ASTDT), and Sequence Number (AESEQ) and flag the first reco
AOCC02FL (1st Occurrence 02 Flag for Serious): Subset to TRTEMFL='Y' and AESER='Y' and sort by Subject (USUBJID), Start Date (ASTDT), and Sequence Number (AESEQ) and flag the first record (set AOCC02FL='Y') within each Subject
CQ01NAM (Customized Query 01 Name): If AEDECOD contains any of the character strings of ('APPLICATION', 'DERMATITIS', 'ERYTHEMA', 'BLISTER') OR if AEBODSYS='SKIN AND SUBC UTANEOUS TISSUE DISORDERS' but AEDECOD is not in ('COLD SWE

CDISC pilot define.xml, credited to CDISC. Quotes normalised; the 'SUBC UTANEOUS' spelling is in the source.

How this was checked

Result

Generated by Claude on 2026-10-20; Python re-run 2026-10-24.

Worked example, recomputed. A script recomputed the values from the data and they matched or were flagged. Statements a script cannot test were checked by a second Claude agent.

Matched10 of 14 derived columns match on all 1,191 records.
CQ01NAM, AOCC01FL181 and 84 records differ, from a typo inside the define text. With the spelling fixed both match on all records.
ADURN, ADURU4 records each differ. The production program computes duration before imputing the start day; neither the define nor the excerpt says so.
GapThe define says ADURN and ADURU; the SAS program in the repository names the variable ADUR. The program is not the exact one that built the dataset.

Prompt shortened for this page. The output shown came from the earlier run of the longer prompt (2026-10-20).

Re-check on 2026-10-24. The AI's Python and the comparison script re-run with Python 3.14 and pandas 3.0: the same counts (CQ01NAM 181, AOCC01FL 84, ADURN and ADURU 4 each). Code only: the AI was not re-run. No R script exists for this workflow.

The longer prompt that was checked

Below are the ADAE derivation comments from define.xml (CDISC pilot) and the two input files. For each variable write numbered pseudocode a programmer could implement without seeing the define: inputs, order of steps, handling of missing and partial values. Then write Python (pandas) that implements it, reading sdtm_ae.xpt and adam_adsl.xpt (pd.read_sas with format='xport', encoding='latin1'), and run it. Where the define text is ambiguous, contradictory, or looks like a typo, say so and state the choice you made instead of silently picking one. Print counts per derived variable so I can check them. Do not invent rules the text does not give.

[derivation text and input file notes pasted here]

A one-line prompt for comparison

Prompt: Write pseudocode for the derivations in the define file

I don't have the define file in front of me, so here is a generic pattern for turning define.xml derivations into pseudocode.

For each derived variable:
1. Identify the source dataset and variables (for example ADSL, ADAE, SDTM AE).
2. Write the derivation in plain steps.
3. Handle missing values and flags.

Example pseudocode (AE analysis dataset):

  READ AE, ADSL
  MERGE AE with ADSL by USUBJID
  ASTDT = convert AESTDTC to a date
  AENDT = convert AEENDTC to a date
  ASTDY = ASTDT - TRTSDT + 1
...

All 5 checks

  1. Ask which step runs first. The production program computes duration before imputing the start day; the define does not say so.
  2. Do not treat define.xml as the specification of record when it disagrees with the program or the data.

Sources

Scripts

Related workflows

All workflows. How we check. Public data only. Drafts for review, not validated output.

Get one workflow a week

Unsubscribe anytime. Privacy.