Executive Summary: The "No Hardcoding" Rule
Under 21 CFR Part 11 and ICH E6(R2) ALCOA+ principles, clinical programmers are strictly prohibited from altering patient clinical data in SAS memory. Writing IF USUBJID='...' THEN BRTHDTC='...' destroys regulatory audit trails and creates an unverified discrepancy between the hospital source chart and the submission dataset. Even for glaring typos, programmers must write automated Data Quality Checks (DQCs) that empower Clinical Data Management (CDM) to issue electronic queries back to the investigative site. SDTM mappings must retain a pristine 1-to-1 lineage back to the raw eCRF audit log.
Figure 1: Regulatory Source Data Lineage — Hospital Source, EDC Audit Logs, Compliant DQC Query Loops, and 1-to-1 SDTM Traceability.
The 1926 Birth Year Temptation #
Imagine you are running the initial SDTM mapping program for the Demographics (DM) domain on an oncology Phase III trial. As you inspect your frequency outputs, you spot Subject ABC-101-042 with a recorded birth year of 1926.
The inclusion criteria for the protocol restrict enrollment to adults aged 18 to 65. The patient enrolled in 2024. If they were truly born in 1926, they would be 98 years old—a blatant protocol violation. But you look at the screening date and other lab records; clearly, the clinical research coordinator at the hospital site struck the wrong key: the patient was almost certainly born in 1996 (age 28).
To a junior programmer under pressure to deliver mock tables before the Friday project review, the solution seems trivial:
DATA sdtm.dm;
SET raw.edc_dm;
IF usubjid = 'ABC-101-042' AND brthdtc = '1926-04-12' THEN DO;
brthdtc = '1996-04-12'; /* Typo fix */
age = 28;
END;
RUN;
The log is clean. The tables compile without errors. The summary statistics look pristine. But you have just committed what biostatistical leadership calls the Cardinal Sin of Clinical SAS Programming.
The Regulatory Trap: 21 CFR Part 11 & ALCOA+ #
To understand why hardcoding fixes in SAS is unacceptable, you must look outside programming syntax and examine the legal framework governing clinical trials: Title 21 CFR Part 11 and ICH E6(R2) Good Clinical Practice (GCP).
Clinical data must adhere to the ALCOA+ framework:
- Attributable: Every single observation, change, and deletion must be unambiguously linked to an authenticated individual with the legal authority to enter it. A statistical programmer sitting at a CRO or sponsor desk has no legal standing to modify a patient's medical history.
- Legible & Traceable: There must be an unbroken audit trail demonstrating the original value, who changed it, the exact timestamp of the change, and the documented clinical reason for the revision.
- Contemporaneous: Changes must be documented at the moment they occur at the investigative clinical site.
- Original: The data in the regulatory submission must trace back to the primary source document (hospital electronic health record or paper clinic chart).
- Accurate: Accuracy is verified through investigator sign-off, not programmer guesswork.
When you execute that IF-THEN override in SAS, you break ALCOA+ completely. The source Electronic Data Capture (EDC) system still holds 1926-04-12. The clinical site knows nothing about your change. The Principal Investigator never signed off on it. You have created an unverified phantom record that exists only in your SAS work session.
The Anatomy of an Inspection Finding #
How does this actually get caught? Regulators do not just read summary reports; inspectors examine clinical trial sites and sponsor headquarters during audits.
Inspectors pull a random sample of enrolled subjects from the submitted DM.xpt dataset. They pull the hospital medical records for Subject ABC-101-042. Then they pull the EDC electronic audit log from Medidata Rave or Veeva EDC.
The inspector compares them:
• Hospital EHR: Birth Date recorded as April 12, 1996.
• EDC System (Raw eCRF): Transcribed in error as April 12, 1926. Electronic signature signed by PI.
• Submitted SDTM (DM.xpt): Birth Date submitted as April 12, 1996.
• EDC Audit Trail: ZERO queries issued. ZERO audit entries. ZERO investigator amendments.
Inspectors ask the Lead Biostatistician: "Who authorized the alteration of this patient's date of birth in the submission dataset, and where is the documented audit trail?"
The answer is found buried in line 84 of an unvalidated SAS mapping script. That finding produces an immediate formal inspection citation citing failure to maintain adequate and accurate case histories (21 CFR 312.62) and failure to maintain secure, computer-generated, time-stamped audit trails (21 CFR 11.10(e)). In severe cases, it calls into question the integrity of the entire safety database.
The Compliant 4-Step Query Loop #
If you cannot fix dirty data in SAS, what is the professional responsibility of a clinical programmer when anomalies arise?
You execute the Compliant Data Quality Check (DQC) Query Loop:
- Step 1: Write Automated DQC Validation Macros: Programmers build standardized discrepancy macros that screen raw EDC tables for biological impossibilities, chronological conflicts (e.g. AE start date prior to informed consent), and protocol violations.
- Step 2: Generate Query Listings for CDM: The program outputs a formatted spreadsheet or discrepancy report containing the
USUBJID, visit, form name, variable name, current raw value, and detailed discrepancy rationale. - Step 3: Clinical Data Management Issues Site Query: The CDM coordinator reviews the listing and issues a formal electronic query in the EDC system (e.g. Medidata Rave). The investigative site coordinator pulls the hospital paper chart, confirms the typographical error, enters the correct value (
1996-04-12), and provides a documented reason for change ("Typographical error corrected per source medical records"). The Principal Investigator re-signs the eCRF. - Step 4: Clean Export Streams to SDTM: In the next raw EDC database extract, the corrected data streams into SAS naturally. The SDTM mapping script maps the cleaned field directly to
BRTHDTCwith zero manual intervention.
Production SAS DQC Macro Example #
Here is how senior biostatistical teams handle discrepancies cleanly and reproducibly:
COMPLIANT PRODUCTION WORKFLOW: Automated DQC Discrepancy Check
Outputs formal query candidates for Clinical Data Management.
============================================================== */
PROC SQL;
CREATE TABLE work.dqc_dm_birth_dates AS
SELECT
dm.USUBJID,
dm.SITEID,
dm.BRTHDTC AS RAW_VALUE,
'BRTHDTC' AS VARIABLE_NAME,
'Birth year indicates patient age > 90 or negative. Potential typographical error.' AS QUERY_RATIONALE
FROM raw.edc_dm AS dm
WHERE INPUT(SUBSTR(dm.BRTHDTC, 1, 4), 4.) < (YEAR(TODAY()) - 90)
OR INPUT(SUBSTR(dm.BRTHDTC, 1, 4), 4.) > YEAR(TODAY());
QUIT;
Allowed Transformations vs. Prohibited Overrides #
Does this mean you can never transform data in a SAS DATA step? Of course not. The critical distinction is between standardized transformations (governed by CDISC Implementation Guides) and unauthorized clinical overrides.
Define-XML 2.0 Origin Implications #
Every dataset in a modern FDA submission package is accompanied by a machine-readable data definition file: Define-XML 2.0.
For every single variable in an SDTM domain, the sponsor must explicitly declare the Origin attribute:
Origin="eCRF": Collected directly on the electronic Case Report Form by site staff.Origin="Derived": Calculated programmatically via a mathematical or algorithmic rule specified in the metadata.Origin="Assigned": Populated by static sponsor rules (e.g.STUDYIDorDOMAIN).Origin="Predecessor": Directly copied from an existing variable in another domain (e.g.DM.RFSTDTCcopied intoADSL.TRTSDTM).
When you submit SDTM DM.BRTHDTC, its declared Origin is eCRF. If an agency validator inspects the submitted SAS Transport (.xpt) file against the raw EDC transfer and discovers you altered the birth year via hardcode, your Define-XML metadata is legally fraudulent.
Summary: Protect the Audit Trail at All Costs #
Clinical SAS programming is not web development where you hotfix bugs directly in production code. You are participating in a legal, regulatory, and ethical chain of custody designed to protect human clinical trial participants and ensure drug efficacy.
Next time you see an obvious typo in an EDC dataset:
- Do not touch it in your DATA step.
- Write an automated discrepancy check.
- Deliver the query listing to Clinical Data Management.
- Let the investigator fix the source audit log.
EDC Raw Data vs. SDTM Traceability: The "No Hardcoding" Rule #
Review our encyclopedic Knowledge Hub guide covering 21 CFR Part 11 electronic records mandates, ALCOA+ audit trails, and automated DQC query workflows.
Lesson 1.03: Protocol Deviations & Clinical Data Audits #
Master the data cleaning pipeline, discrepancy management protocols, and how to write automated SAS validation macros for clinical trial data hygiene.