Tutorials › Biostatistics › Validating SAS Programs in Regulated Environments

Regulated Clinical Programming

Validating SAS Programs in Regulated Environments

A practical guide to validating SAS programs used in regulated clinical research, including risk assessment, validation planning, independent programming, test cases, QC, traceability, change control, documentation, electronic records, and inspection readiness.

Intermediate 20 min read

What You'll Learn

  • Why SAS program validation is different in a regulated environment
  • How to build a risk-based validation strategy
  • How independent programming and QC differ
  • How to design effective validation test cases
  • How to maintain traceability, documentation, and audit evidence
  • How to validate SAS outputs and remain inspection-ready

Introduction

In clinical research, SAS programs frequently transform raw clinical data into analysis datasets, tables, listings, figures, and other outputs that may support important regulatory decisions.

In an ordinary programming environment, discovering a defect may simply mean fixing the code and rerunning it.

In a regulated environment, the problem is broader.

The organization must be able to demonstrate that the computerized process is fit for its intended use, that the development and verification activities were appropriately controlled, and that the resulting records are reliable and traceable.

Key idea: Validation is not synonymous with "having a second programmer check the SAS code." A defensible validation process addresses the intended use, risk, requirements, implementation, testing, deviations, changes, documentation, and retained evidence.

What Does "Validation" Mean?

In regulated computerized systems, validation is generally understood as a documented process that provides a high degree of assurance that a system or computerized process consistently performs according to predetermined specifications and quality attributes.

For SAS programming, this concept must be applied to the complete analytical process rather than only to the syntax of an individual program.

For example, consider a program producing an adverse-event summary table. The validation question is not merely:

$$ \text{Does the SAS code run without errors?} $$

The more meaningful question is:

$$ \text{Does the controlled process produce the intended result from the correct data?} $$

That distinction is fundamental.

Verification vs. Validation

The terms verification and validation are related but should not automatically be treated as interchangeable.

Concept Typical Question
Verification Was the product built correctly according to its specifications?
Validation Does the resulting process or system fulfill its intended use?
Quality control Were the required checks performed and were discrepancies resolved?
Testing Does the implementation behave as expected under defined conditions?
Review Has an appropriately qualified person examined the relevant evidence?

A strong regulated programming process uses these concepts together rather than relying on any single activity.

Why SAS Programs Need Special Attention

A SAS program may look simple while still having substantial regulatory impact.

Consider a program that derives treatment-emergent adverse events.

A one-character error in a date comparison could change whether an event is classified as treatment-emergent.

A join that unintentionally duplicates subjects could inflate event counts.

An incorrect denominator could change percentages throughout an efficacy table.

A format change could make a result appear different even when the underlying value is unchanged.

These errors may not produce SAS errors or warnings.

Important: A SAS log without errors is not evidence that a program is correct. Many of the most consequential programming defects are logically valid SAS statements that produce incorrect results.

The SAS Validation Lifecycle

A regulated validation process should be planned rather than improvised after programming is complete.

Figure 1. Typical Risk-Based SAS Validation Lifecycle
Validation is a lifecycle activity extending from intended use and requirements through testing, approval, release, and controlled change.
01 Intended Use
→
02 Risk Assessment
→
03 Requirements
→
04 Development
→
05 Verification
→
06 Approval
→
07 Change Control

Start With Intended Use

Before deciding how much testing a SAS program requires, determine what the program is intended to accomplish.

For example:

  • Generate an exploratory analysis
  • Produce an internal data review
  • Create a production ADaM dataset
  • Generate a primary efficacy table
  • Generate a regulatory submission figure
  • Support a clinical database lock
  • Produce a safety analysis used in a submission

The intended use provides the foundation for the risk assessment.

Risk-Based Validation

Not every SAS program has the same level of risk.

A temporary exploratory program used by a statistician to investigate an outlier does not necessarily warrant the same validation controls as a program producing a primary efficacy endpoint for a regulatory submission.

A practical risk assessment considers factors such as:

  • Impact on patient safety
  • Impact on subject rights and confidentiality
  • Impact on data integrity
  • Impact on primary or key secondary endpoints
  • Regulatory significance
  • Complexity of derivations
  • Likelihood of programming error
  • Degree of manual intervention
  • Reusability of the program
  • Complexity of the input data

Example Risk Matrix

Figure 2. Illustrative Risk-Based Validation Matrix
An organization's SOPs should define the actual risk methodology. This example illustrates the principle rather than prescribing a universal scoring system.
Impact ↓ / Complexity →
Low
Moderate
High
Very High
Low
Low
Low
Moderate
Moderate
Moderate
Low
Moderate
Moderate
High
High
Moderate
Moderate
High
High
Critical
Moderate
High
High
Very High
Best practice: Risk-based validation does not mean high-risk programs receive testing and low-risk programs receive none. It means the depth, independence, formality, and documentation of verification activities are proportionate to the potential impact of failure.

Validation Starts Before Coding

One of the most common mistakes is treating validation as an activity that begins after the SAS programmer finishes coding.

By that point, important decisions may already have been made without adequate documentation.

A stronger lifecycle begins with:

1
Define intended use. Establish what the program is supposed to accomplish.
2
Define requirements. Translate the statistical or business requirement into testable expectations.
3
Assess risk. Determine the appropriate level of control and testing.
4
Develop. Create the SAS program using controlled standards.
5
Verify. Perform predefined QC and validation testing.
6
Resolve. Investigate discrepancies and document conclusions.
7
Approve and release. Ensure the correct version is authorized for use.

Requirements Must Be Testable

A requirement such as:

"Create the demographic table."

is too vague to provide strong validation evidence.

A better requirement identifies:

  • Population
  • Variables
  • Statistics
  • Grouping
  • Missing-value handling
  • Display rules
  • Rounding
  • Sorting
  • Output format

For example:

Requirement:
For the Safety Population, summarize age by treatment group
using N, mean, standard deviation, median, minimum, and maximum.
Display one decimal place for continuous statistics.

That requirement can be translated into explicit test cases.

What Makes a Good Test Case?

A useful validation test should have a defined:

Element Example
Test ID DM-AGE-001
Requirement Age summary by treatment
Input Controlled demographic dataset
Condition Three subjects in treatment group A
Expected result Mean age = 52.3
Actual result 52.3
Status Pass
Evidence Output and comparison record

The objective is to make the expected behavior explicit before the result is reviewed.

Independent Programming

Independent programming is a common approach to validating clinical programming outputs.

The production programmer creates the primary implementation.

A second programmer independently develops an alternative implementation or performs an appropriately independent verification, depending on the organization's procedures and the risk of the output.

The critical concept is independence of reasoning.

Independent does not necessarily mean "copy the original program." If the QC programmer simply reproduces the same code structure, assumptions, and mistakes, the second program may provide much less assurance than a genuinely independent approach.

Example: Independent Validation of a Mean

Suppose the production SAS program calculates the mean age:

proc means data=adam.adsl n mean std median min max;
    class trt01p;
    var age;
run;

An independent programmer might calculate the same statistic using a different approach, such as a controlled SQL aggregation or an alternative SAS procedure, provided the method is appropriate and itself controlled.

proc sql;
    create table qc_age as
    select trt01p,
           count(age) as n,
           mean(age) as mean_age
    from adam.adsl
    group by trt01p;
quit;

The two results can then be compared.

Why Independent Programming Is Valuable

Suppose both programmers obtain the same incorrect result because both misunderstood the specification.

That is a requirements problem rather than a simple coding problem.

Independent validation is most effective when it can challenge:

  • Programming logic
  • Dataset selection
  • Population definitions
  • Derivation assumptions
  • Boundary conditions
  • Sorting rules
  • Missing-data handling
  • Statistical calculations

Source Code Review

Source-code review remains useful even when independent output programming is performed.

A reviewer may examine:

  • Variable references
  • Macro parameters
  • Join conditions
  • BY-group processing
  • Sort requirements
  • Population filters
  • Missing-value logic
  • Date calculations
  • Formats and informats
  • Output destinations
  • Error handling

However, source-code review alone is not a substitute for testing the resulting behavior.

Testing the Program Is More Than Reviewing the Code

A program can look reasonable while still producing the wrong answer.

For example:

if trtsdt <= aestdt <= trtedt then trtemfl = "Y";

may look perfectly reasonable to a reviewer.

But the correct treatment-emergent definition may require additional rules around partial dates, same-day events, pre-treatment events, or treatment exposure windows.

The specification, not visual plausibility of the code, determines correctness.

Positive and Negative Testing

Good validation testing includes both expected and unexpected conditions.

Positive Testing

Positive tests confirm that valid inputs produce the expected outputs.

For example:

  • A subject with a valid treatment date
  • A laboratory result within the reference range
  • A valid analysis visit
  • A complete baseline record

Negative Testing

Negative tests examine situations that could cause erroneous behavior.

  • Missing treatment date
  • Missing baseline value
  • Duplicate records
  • Unexpected visit values
  • Extreme numeric values
  • Invalid character values
  • Subjects outside the analysis population
Why negative testing matters: Many clinical-programming defects occur at boundaries, exceptions, or unusual records rather than in ordinary observations.

Boundary Testing

Boundary conditions deserve explicit attention.

Suppose a protocol defines an age category:

< 65 years
65–74 years
≥ 75 years

Testing only ages 40 and 80 does not adequately test the classification logic.

The important cases include:

$$ 64,\quad65,\quad74,\quad75 $$

These observations test the boundaries where logic is most likely to fail.

Testing Date Logic

Clinical-trial SAS programs frequently contain date logic.

Potential boundary conditions include:

  • Event on first-dose date
  • Event one day before first dose
  • Event one day after last dose
  • Missing end date
  • Partial dates
  • Leap years
  • Year boundaries
  • Visit windows

Date derivations should therefore have targeted test cases rather than relying only on ordinary patient records.

Testing Missing Values

Missing values are particularly important in SAS because missing numeric and character values have specific SAS behavior.

For example:

if aval < 10 then flag = "Y";

requires careful consideration when aval is missing.

A validation test should explicitly determine the expected behavior for:

  • Missing numeric values
  • Missing character values
  • Blank dates
  • Partial dates
  • Missing baseline values
  • Missing treatment assignments

Testing Duplicate Records

Duplicate records can silently affect clinical outputs.

Consider:

proc sql;
    create table merged as
    select a.*, b.aval
    from adsl as a
    left join adlb as b
      on a.usubjid = b.usubjid;
quit;

If the intended relationship is one record per subject but the laboratory dataset contains multiple records per subject, the resulting dataset may contain multiple copies of subject-level records.

Validation should therefore include tests for expected record relationships.

Record Counts Are Validation Evidence

Simple counts are often among the most useful QC checks.

Examples include:

proc sql;
    select count(*) as n_records,
           count(distinct usubjid) as n_subjects
    from adam.adsl;
quit;

Useful reconciliation checks include:

  • Input record count
  • Output record count
  • Distinct subject count
  • Number of treatment groups
  • Number of observations per subject
  • Number of missing values
  • Number of records excluded

Data Lineage and Traceability

A regulated analysis should allow an important result to be traced backward.

For example:

1
Table cell — treatment-emergent adverse-event percentage
2
Analysis dataset — subject-level or event-level analysis records
3
Derived variables — treatment-emergent flag and analysis population flag
4
Source data — controlled clinical data
5
Specification — defines how the result is supposed to be derived

Traceability allows a reviewer to understand not only what the final number is, but where it came from and why it was produced.

Program Traceability

At the programming level, traceability may connect:

Artifact Example
Requirement Primary efficacy endpoint definition
Specification ADaM derivation specification
Program adeff.sas
Dataset ADaM BDS efficacy dataset
Output Primary efficacy table
QC evidence Independent comparison
Approval Controlled review record

Validation Documentation

A regulated programming environment typically requires more documentation than simply retaining the final SAS program.

Depending on the organization's procedures and the applicable regulatory framework, documentation may include:

  • Validation plan
  • Risk assessment
  • User or functional requirements
  • Technical specifications
  • Programming specifications
  • Test scripts
  • Test results
  • Defect or deviation records
  • Traceability matrix
  • Review records
  • Approval records
  • Change-control records
  • Training records
  • System documentation

The Validation Plan

A validation plan establishes the overall strategy.

It should address questions such as:

  • What is being validated?
  • What is the intended use?
  • What risks are being controlled?
  • What testing is required?
  • Who performs the testing?
  • Who reviews and approves the evidence?
  • What constitutes acceptable evidence?
  • How are deviations handled?
  • How are changes controlled?
  • What records must be retained?

Validation Summary Report

At the conclusion of a validation activity, a summary report can provide a controlled overview of what was performed.

Typical information includes:

  • Scope
  • Validation activities performed
  • Test execution status
  • Deviations
  • Outstanding issues
  • Risk assessment conclusions
  • Approval status

Validation of a SAS Macro

Reusable SAS macros deserve particular attention.

A macro used across dozens of tables can have a much larger impact than a one-time exploratory program.

For example:

%macro pct(n=, denom=);
    &n / &denom * 100
%mend;

A defect in a heavily reused macro could propagate to many outputs.

Macro validation should therefore consider:

  • Expected parameter values
  • Missing parameters
  • Invalid parameters
  • Boundary conditions
  • Different input structures
  • Different denominators
  • Character versus numeric inputs
  • Output formatting
  • Reuse across studies

Reusable Code Requires Governance

A validated macro is not automatically validated forever.

Changes to:

  • Macro logic
  • Dependencies
  • SAS version
  • Operating system
  • Input assumptions
  • Output requirements

may require impact assessment and potentially additional testing.

SAS Version and Environment

The execution environment matters.

A program may behave differently because of changes in:

  • SAS release
  • Operating system
  • Database drivers
  • External libraries
  • Macro libraries
  • Encoding
  • File-system behavior
  • Third-party components

The validation strategy should therefore identify the relevant computational environment.

Do not assume portability. A SAS program that produces an expected result on one controlled environment should not automatically be considered validated on a substantially different environment without appropriate assessment.

SAS Logs as Validation Evidence

The SAS log is useful evidence, but it has limitations.

Review should consider:

  • Errors
  • Warnings
  • Uninitialized variables
  • Invalid numeric data
  • Unexpected notes
  • Merge behavior
  • Record counts
  • Variable creation
  • Sort requirements
  • Unexpected overwrites

A clean log is therefore one component of QC, not the entire validation.

Important SAS Log Checks

NOTE: MERGE statement has more than one data set with repeats of BY values.
NOTE: Variable X is uninitialized.
NOTE: Invalid argument to function INPUT.
WARNING: Apparent symbolic reference XYZ not resolved.

Such messages may or may not represent defects, but they should be evaluated rather than automatically ignored.

Output Validation

Validation should examine the final output, not merely the intermediate program.

For a clinical table, QC may include:

  • Title
  • Population
  • Column headers
  • Treatment labels
  • Units
  • Statistics
  • Denominators
  • Percentages
  • Rounding
  • Sorting
  • Footnotes
  • Page breaks
  • Pagination
  • Suppression rules

Table-Level Validation Example

Suppose a table contains:

Treatment A
N = 100

Responders = 42
Response Rate = 42.0%

Validation should not stop after confirming that the number 42 appears in the output.

The QC process should establish:

$$ \text{Response Rate} = \frac{42}{100}\times100 = 42.0\% $$

and independently confirm that:

  • The numerator represents the correct responder definition.
  • The denominator represents the correct analysis population.
  • Subjects are counted once.
  • The rounding rule is correct.
  • The output label accurately describes the statistic.

Figure Validation

Figures require both numerical and visual validation.

For example, a Kaplan-Meier plot should be checked for:

  • Analysis population
  • Event definition
  • Censoring
  • Time scale
  • Survival estimates
  • Number-at-risk values
  • Confidence intervals
  • Axis labels
  • Legend
  • Titles and footnotes

A plot can contain numerically correct survival estimates but still be incorrectly labeled.

Listings Require Different QC

Listings often require row-level inspection.

Important checks include:

  • Subject ordering
  • Visit ordering
  • Date formatting
  • Units
  • Missing values
  • Duplicate records
  • Population selection
  • Page breaks
  • Continuation headers
  • Confidentiality requirements

Comparing Production and QC Outputs

Automated comparison tools are highly valuable in clinical programming.

For example:

proc compare
    base=prod.adsl
    compare=qc.adsl
    criterion=0
    listall;
run;

The exact comparison strategy should reflect the type of artifact being validated.

For datasets, record-level and variable-level comparison may be appropriate. For formatted reports, a combination of structured comparison and visual inspection may be required.

Do Not Blindly Trust PROC COMPARE

A zero-difference comparison is useful evidence, but it does not prove that both datasets are correct.

If production and QC programs contain the same incorrect derivation, they can agree perfectly.

Core principle: Agreement demonstrates consistency between two implementations. It does not, by itself, establish correctness against the underlying requirement.

Requirement-Based Testing vs. Output Comparison

Approach Strength Limitation
Independent programming Challenges implementation logic Can reproduce specification misunderstandings
PROC COMPARE Efficiently detects differences Agreement does not prove correctness
Source-code review Identifies obvious logic issues May miss behavioral defects
Test cases Tests predefined expected behavior Coverage must be designed well
Clinical review Provides subject-matter context Not a substitute for technical testing

Validation Should Use Multiple Evidence Sources

A mature validation strategy combines evidence rather than depending on a single QC method.

A
Requirement review — confirm what the output is supposed to represent.
B
Program review — examine implementation logic.
C
Independent check — challenge the calculation or result.
D
Automated comparison — identify unexpected differences.
E
Visual review — confirm the final presentation.
F
Documentation — retain evidence and disposition discrepancies.

Deviation Management

Not every failed test means that the entire validation has failed.

A failed test should trigger investigation.

Potential causes include:

  • Programming defect
  • Incorrect test expectation
  • Specification ambiguity
  • Input-data problem
  • Environment issue
  • Documentation error
  • Intentional difference

The discrepancy should be documented, investigated, corrected or justified, and appropriately reviewed according to the organization's procedures.

Example Defect Record

Field Example
Defect ID VAL-2026-014
Program adtte.sas
Issue Subjects with missing end dates were incorrectly classified
Severity Major
Impact Potential effect on time-to-event analysis
Root cause Missing-date rule was not implemented
Correction Program updated and rerun
Regression testing Completed

Change Control

A validated SAS program should not be treated as an uncontrolled text file.

Changes should be managed through an established change-control process.

A change may be triggered by:

  • Protocol amendment
  • Statistical analysis plan amendment
  • Data correction
  • Programming defect
  • New regulatory requirement
  • Software upgrade
  • Output-format change
  • New analysis requirement

Impact Assessment After a Change

When a program changes, ask:

$$ \text{What else could this change affect?} $$

For a shared macro, the answer may include dozens of tables.

For a change to an ADaM derivation, downstream efficacy and safety outputs may also be affected.

The impact assessment should therefore identify affected:

  • Programs
  • Datasets
  • Tables
  • Listings
  • Figures
  • Specifications
  • Validation evidence

Regression Testing

Regression testing determines whether a change unintentionally affected existing functionality.

For example, changing a demographic macro may require retesting:

  • Demographic tables
  • Baseline characteristic tables
  • Subject listings
  • Related outputs using the same macro

The appropriate regression scope should be determined by the change impact and risk.

Version Control

Version control is an important component of controlled programming.

A version-control system can provide:

  • Change history
  • Author attribution
  • Version identification
  • Branching and merging
  • Rollback capability
  • Review workflow

Git is increasingly used for SAS programming, but the tool itself does not create compliance.

Important: A Git repository is not automatically a validated system. The organization must determine how version control, access, review, approvals, electronic records, and retention fit within its controlled processes.

Electronic Records and Electronic Signatures

When electronic records and signatures are used in regulated activities, organizations may need to consider applicable requirements governing electronic records, signatures, security, access, audit trails, and record retention.

In the United States, 21 CFR Part 11 is particularly relevant to electronic records and electronic signatures maintained or relied upon under applicable FDA requirements.

The exact regulatory obligations depend on the system, records, use case, and applicable regulations.

Audit Trails

An audit trail helps establish who performed an action, what changed, and when the change occurred.

For a regulated programming workflow, relevant controlled-system audit information may include:

  • Program changes
  • Specification changes
  • Approval actions
  • Test execution
  • Defect resolution
  • Release activities

The objective is to make significant changes reconstructable.

Access Control

A controlled programming environment should restrict access according to role and need.

Examples include:

  • Developer access
  • QC access
  • Reviewer access
  • Approver access
  • Release-manager access
  • System-administrator access

Segregation of duties can reduce the risk that one person can make an unreviewed change and release it without appropriate oversight.

Computer System Validation vs. SAS Program Validation

These concepts should not be conflated.

A regulated organization may validate:

  • The SAS computing environment
  • Supporting applications
  • Data-management systems
  • Statistical programming workflows
  • Individual analytical programs

The scope and evidence depend on the intended use and risk.

Validating the SAS installation does not automatically validate every SAS program written in that environment.

Conversely, validating an individual program does not necessarily establish that the surrounding computerized environment is suitable for regulated use.

Infrastructure Validation

Organizations may have controls around:

  • Servers
  • Operating systems
  • Databases
  • Network infrastructure
  • Storage
  • Backup and recovery
  • Identity management
  • Security monitoring

These controls operate at a different layer from program-level validation.

IQ, OQ, and PQ

Traditional validation terminology sometimes divides system qualification into:

Term General Purpose
IQ — Installation Qualification Provides evidence that the system or environment was installed appropriately.
OQ — Operational Qualification Provides evidence that the system operates according to specified requirements.
PQ — Performance Qualification Provides evidence that the system performs effectively for its intended use.

Modern risk-based computerized-system approaches do not always require these traditional labels or a rigid three-phase structure.

The important concept is that the validation approach should be scientifically and risk appropriately justified.

SAS Program Validation Is Not the Same as Software Vendor Validation

If an organization uses a commercial statistical system, the vendor may provide documentation about the software product.

That does not automatically validate the organization's specific use of SAS.

The organization remains responsible for demonstrating that its particular configuration, procedures, programs, data, and intended uses are adequately controlled.

Validation of Statistical Derivations

Statistical derivations deserve special attention because a mathematically correct SAS implementation can still be wrong if it implements the wrong statistical definition.

Consider a treatment difference:

$$ \Delta = \bar{X}_{T} - \bar{X}_{C} $$

Validation must establish:

  • Which subjects belong to each population
  • Which treatment variable is used
  • Which analysis value is used
  • How missing values are handled
  • Whether the difference is treatment minus control
  • Which statistical method is required
  • How rounding is applied

Validation of ADaM Derivations

ADaM datasets are particularly important because they provide analysis-ready structures supporting many downstream outputs.

Validation should consider:

  • Population flags
  • Baseline flags
  • Analysis values
  • Analysis dates
  • Analysis visits
  • Parameter definitions
  • Change from baseline
  • Percentage change
  • Treatment variables
  • Imputation variables

Example ADaM Derivation

Suppose:

$$ CHG = AVAL - BASE $$

and:

$$ PCHG = \frac{AVAL-BASE}{BASE}\times100 $$

Validation should test:

BASE AVAL Expected CHG Expected PCHG
100 120 20 20%
100 80 -20 -20%
100 100 0 0%
0 20 20 Defined by specification
Missing 80 Defined by specification Defined by specification

The final two cases are particularly important because the expected behavior cannot simply be assumed from the mathematical formula.

Testing Macro Variables

Macro-driven clinical programming can introduce defects that are difficult to detect through ordinary data review.

For example:

%let where_clause = trt01pn in (1,2);

proc means data=adam.adsl;
    where &where_clause;
    var age;
run;

Validation should establish that:

  • The macro variable resolves correctly.
  • The intended population is selected.
  • Unexpected values are handled appropriately.
  • The macro behaves correctly under alternative valid parameters.

Testing Reusable TLF Frameworks

Large clinical programming organizations frequently use standardized frameworks for table, listing, and figure production.

A framework may control:

  • Titles
  • Footnotes
  • Pagination
  • Column structures
  • Statistical formatting
  • Output naming
  • RTF/PDF generation
  • Excel generation

The framework itself can become a high-impact reusable component.

Its validation should therefore consider representative use cases across the range of supported configurations.

Representative Testing

If a macro supports ten table types, testing only one simple table may provide limited assurance.

Representative testing should exercise materially different configurations, such as:

  • Continuous statistics
  • Categorical statistics
  • Multiple treatment groups
  • Subgroups
  • Multi-level headers
  • Long labels
  • Missing values
  • Zero denominators
  • Large outputs

Validation and Zero Denominators

Percent calculations require explicit rules for zero denominators.

For:

$$ \frac{N}{D}\times100 $$

what happens when:

$$ D=0 $$

should be defined before the program is considered complete.

Possible output conventions might include:

  • Blank
  • Not estimable
  • Not applicable
  • Zero

The correct choice is specification-dependent.

Clinical Review Is Part of the Quality Process

Statistical programmers should not be expected to determine every clinical interpretation independently.

Appropriate subject-matter review may be needed for:

  • Endpoint definitions
  • Safety classifications
  • Response criteria
  • Protocol populations
  • Clinical significance
  • Unexpected patterns

The programmer validates the implementation, while qualified clinical and statistical reviewers provide domain context.

Inspection Readiness

An inspection-ready programming environment should allow an organization to answer questions such as:

  • Who wrote this program?
  • Which version was used?
  • What requirement does it implement?
  • What data did it use?
  • How was it tested?
  • Who performed QC?
  • Were there discrepancies?
  • How were discrepancies resolved?
  • Who approved the result?
  • Can the final result be reproduced?
Inspection mindset: Do not design documentation merely to prove that nothing went wrong. Design it so that another qualified person can reconstruct what happened, why it happened, and why the resulting output was accepted.

Reproducibility

A regulated analysis should be reproducible from controlled inputs and controlled programs.

Ideally, the workflow should allow a qualified person to determine:

$$ \text{Inputs} \rightarrow \text{Programs} \rightarrow \text{Derived Data} \rightarrow \text{Outputs} $$

with sufficient metadata and documentation to understand each transformation.

Reproducibility Is More Than Rerunning SAS

A program may not be reproducible if it depends on:

  • Manual edits
  • Uncontrolled spreadsheets
  • Undocumented external files
  • Hard-coded temporary paths
  • Unrecorded parameter settings
  • Uncontrolled macro libraries
  • Different software versions

Controlled dependencies are therefore part of the validation story.

Manual Intervention

Manual intervention can introduce significant risk.

Examples include:

  • Editing CSV files before SAS import
  • Manually modifying an output dataset
  • Copying values into a spreadsheet
  • Changing a program after execution
  • Manually changing a PDF or RTF output
Best practice: Minimize manual intervention in regulated analytical workflows. Where manual steps are necessary, document, control, review, and validate them according to the applicable procedures.

Hard-Coded Values

Hard-coded values are not automatically prohibited, but uncontrolled hard-coding can make programs difficult to maintain and validate.

For example:

if trt01pn = 1 then trt = "Placebo";
else if trt01pn = 2 then trt = "Drug X";

A specification-driven approach may instead use controlled treatment metadata.

The appropriate solution depends on the study architecture and programming standards.

Validation of Formats

SAS formats can affect what users see without changing the underlying value.

For example:

value sexfmt
    1 = "Male"
    2 = "Female";

Validation should confirm that the format is correct and that it is applied to the intended variable.

Validation of Sorting

Sorting is another apparently simple area that can affect output correctness.

A listing might require:

$$ USUBJID \rightarrow VISITNUM \rightarrow ADT $$

If the program instead sorts alphabetically by visit label, the output may appear plausible while violating the intended analysis order.

Validation of Merges and Joins

Merges deserve explicit testing because many serious clinical-programming errors originate from incorrect relationships between datasets.

Before merging, establish whether the relationship is:

  • One-to-one
  • One-to-many
  • Many-to-one
  • Many-to-many

A many-to-many relationship may create unintended record multiplication.

Example Merge QC

proc sql;
    select usubjid,
           count(*) as n
    from merged
    group by usubjid
    having calculated n > expected_max;
quit;

The exact expected relationship should be determined from the specification.

Validation of Randomization and Treatment Assignment

Treatment variables can affect virtually every downstream clinical analysis.

Validation should reconcile treatment assignments against the controlled source.

Useful checks include:

  • Number of randomized subjects
  • Number treated
  • Planned treatment
  • Actual treatment
  • Analysis treatment
  • Switches or crossover rules

Population Flags

Population flags are frequently reused across outputs.

Examples include:

  • Safety Population
  • Full Analysis Set
  • Intent-to-Treat Population
  • Per-Protocol Population
  • Randomized Population

A defect in a population flag can propagate to many downstream analyses.

High-impact principle: When a derived variable is reused broadly, its validation should reflect its downstream impact rather than being treated as an ordinary one-off variable.

Validation of Primary Endpoints

Primary endpoint programs typically warrant particularly rigorous validation because their results may directly support major regulatory conclusions.

Testing may include:

  • Independent programming
  • Detailed derivation review
  • Boundary testing
  • Subject-level reconciliation
  • Population reconciliation
  • Statistical output comparison
  • Clinical/statistical review
  • Full traceability

Testing the Unexpected

A strong validation strategy deliberately introduces unusual conditions.

For example:

  • A subject with no post-baseline assessment
  • A subject with multiple baseline candidates
  • A subject with duplicate assessments
  • A missing treatment date
  • An assessment outside the expected window
  • A zero denominator
  • An extreme laboratory value
  • A very long text value

The purpose is to discover how the program behaves when real-world data do not look ideal.

Test Coverage

The number of test cases alone is not a meaningful measure of validation quality.

A hundred nearly identical tests may provide less assurance than twenty carefully selected cases covering distinct risks.

A useful conceptual model is:

$$ \text{Validation Coverage} \approx \text{Requirements} + \text{Risk Conditions} + \text{Boundary Conditions} + \text{Representative Data} $$

Traceability Matrix

A traceability matrix connects requirements to implementation and testing.

Requirement Program Test Result
REQ-001: Safety population adsl.sas VAL-001 Pass
REQ-002: Treatment-emergent flag adae.sas VAL-002–006 Pass
REQ-003: AE incidence t_ae.sas VAL-007–012 Pass
REQ-004: Output formatting t_ae.sas VAL-013 Pass

The matrix allows reviewers to identify requirements without adequate test coverage.

Validation Checklist

Figure 3. Practical SAS Validation Checklist
A concise review of the major evidence categories that should be considered for regulated analytical programming.
01
Intended use
Is the purpose of the program clearly defined?
02
Requirements
Are the expected calculations and outputs documented?
03
Risk
Has the impact and complexity been assessed?
04
Controlled code
Is the program version identifiable and controlled?
05
Testing
Are positive, negative, and boundary cases covered?
06
Independent QC
Has an appropriate independent verification been performed?
07
Output review
Has the final table, listing, or figure been checked?
08
Traceability
Can the output be traced to requirements and source data?
09
Discrepancies
Were failures investigated and appropriately documented?
10
Approval
Is the validated version appropriately approved and released?

Common Validation Mistakes

  1. Starting validation after programming is complete. Requirements and risk should influence the validation strategy from the beginning.
  2. Assuming a clean SAS log means the program is correct. Logical errors frequently produce valid SAS execution.
  3. Using PROC COMPARE as the only QC method. Two implementations can agree on the same incorrect result.
  4. Copying the production program for QC. This can reproduce the same assumptions and defects.
  5. Testing only normal records. Boundary and exceptional cases are often where defects appear.
  6. Ignoring requirements. Code review cannot compensate for an unclear definition of the expected result.
  7. Failing to document discrepancies. A defect history is part of the validation evidence.
  8. Changing validated code without impact assessment. Changes may affect downstream outputs.
  9. Relying on manual spreadsheet corrections. Manual intervention can introduce uncontrolled changes.
  10. Confusing tool validation with program validation. A validated SAS environment does not automatically validate every program.
  11. Over-documenting low-risk activities while under-testing high-risk ones. Validation should be proportionate to risk.
  12. Failing to preserve the exact released version. The program used to generate the final result should be identifiable and recoverable.

A Practical Validation Workflow for a TLF

Consider a production table showing adverse-event incidence.

1
Read the specification. Establish the population, treatment groups, event definition, denominator, and display rules.
2
Identify inputs. Determine which controlled datasets and variables are required.
3
Assess risk. Determine the appropriate QC strategy.
4
Develop production code. Program the table according to controlled standards.
5
Run and inspect the log. Investigate errors, warnings, and unexpected notes.
6
Perform independent QC. Recalculate or independently derive the key results.
7
Compare outputs. Reconcile discrepancies between production and QC.
8
Review visually. Confirm titles, labels, statistics, footnotes, and formatting.
9
Document evidence. Retain test results, comparisons, reviews, and discrepancy resolution.
10
Approve release. Ensure only the authorized version is used for the intended purpose.

Example of a Validation Test Script

Test ID:
VAL-AE-007

Requirement:
Subjects with at least one treatment-emergent adverse event
must be included in the AE incidence denominator.

Input:
ADSL and ADAE controlled analysis datasets.

Test condition:
Subject 1007 has an AE beginning on the first dose date.

Expected result:
Subject 1007 is classified as treatment-emergent and is
included in the relevant incidence calculation.

Actual result:
Subject 1007 is included.

Status:
PASS

Evidence:
Validated output, subject-level reconciliation, SAS log,
and comparison report.

The important feature is that the expected behavior was established before the result was accepted.

Unit Testing vs. System-Level Testing

Testing can occur at different levels.

Level Example
Unit Test a date derivation or macro function
Program Test a single ADaM or TLF program
Workflow Test a sequence of dataset and output programs
System Test the controlled environment and supporting infrastructure
End-to-end Trace controlled source data through final output

Using multiple levels can provide stronger assurance than testing only the final report.

End-to-End Validation

An end-to-end test might follow:

$$ SDTM \rightarrow ADaM \rightarrow TLF $$

The validation question becomes whether the final output correctly reflects the intended transformation of the original controlled data.

Validation of Derived Data

For a derived dataset, validation should consider both:

  • Individual derivations
  • Overall dataset structure

Structural checks might include:

  • Expected variables
  • Variable attributes
  • Labels
  • Formats
  • Sort order
  • Key uniqueness
  • Record counts
  • Population coverage

Metadata Validation

A dataset can contain numerically correct values but incorrect metadata.

For example, a variable may have:

Name: AVAL
Label: Change from Baseline
Type: Numeric

when the intended definition actually requires the variable to represent an analysis value.

Metadata should therefore be included in the validation scope when it affects interpretation or downstream processing.

Validation of Formats and Labels

Labels are not merely cosmetic when they communicate statistical meaning.

For example:

Mean (SD)

should not be used if the displayed statistic is actually median (IQR).

Validation should therefore verify semantic accuracy as well as formatting.

When Full Independent Programming May Not Be Appropriate

Not every low-risk programming task necessarily requires a complete independent reimplementation.

Depending on organizational procedures and risk, alternatives may include:

  • Source-code review
  • Targeted test cases
  • Automated checks
  • Output reconciliation
  • Standardized validated components
  • Clinical review

The appropriate approach should be defined by the organization's SOPs, validation methodology, and risk assessment.

Risk-Based Does Not Mean Less Rigorous

A risk-based approach can actually improve validation by directing effort toward the areas where failure matters most.

For example, a primary endpoint derivation may receive extensive independent testing, while a low-impact formatting utility may receive a lighter but documented verification approach.

The key is that the difference is justified, documented, and consistent with the governing quality system.

What Regulators Care About

Regulatory expectations around computerized systems and clinical data broadly center on the reliability, integrity, and suitability of the processes used to generate regulated records and analyses.

For programmers, that translates into practical questions:

  • Can the analysis be reconstructed?
  • Are changes controlled?
  • Are calculations traceable?
  • Are data transformations documented?
  • Are records protected from inappropriate alteration?
  • Are validation activities documented?
  • Are deviations investigated?
  • Can the organization demonstrate control over the process?

Inspection Readiness Checklist

1
Identify the exact program version used for the final analysis.
2
Identify the corresponding input dataset versions.
3
Retrieve the applicable specifications and requirements.
4
Retrieve the validation and QC evidence.
5
Identify all relevant deviations and their disposition.
6
Demonstrate traceability from source data to final output.
7
Demonstrate appropriate review and approval.
8
Demonstrate that subsequent changes were controlled.

Documentation Should Tell a Coherent Story

The strongest validation package is internally consistent.

The requirement should describe what is needed.

The program should implement it.

The test should challenge it.

The result should provide evidence.

The reviewer should be able to understand the conclusion.

$$ \text{Requirement} \rightarrow \text{Implementation} \rightarrow \text{Test} \rightarrow \text{Evidence} \rightarrow \text{Approval} $$

When these pieces do not align, validation becomes difficult to defend.

Validation and GxP Thinking

Clinical statistical programming operates within a broader regulated environment when its outputs support regulated activities.

The precise requirements depend on the organization, study, jurisdiction, system, and intended use.

Therefore, programmers should understand the relevant quality system rather than attempting to apply isolated regulatory phrases mechanically.

What a SAS Programmer Should Know

A statistical programmer working in a regulated environment does not need to be a regulatory lawyer.

But the programmer should understand:

  • Why validation is required
  • What the intended use is
  • How risk affects QC
  • How requirements become tests
  • How independent QC works
  • How discrepancies are documented
  • Why version control matters
  • Why traceability matters
  • Why uncontrolled manual edits are risky
  • How change control works

Practical Programmer Habits

Several everyday habits make regulated validation substantially easier.

  • Use meaningful program headers.
  • Identify program versions consistently.
  • Keep specifications synchronized with implementation.
  • Avoid unexplained hard-coded assumptions.
  • Document unusual derivations.
  • Investigate unexpected SAS log messages.
  • Build reconciliation checks into development workflows.
  • Keep temporary exploratory work separate from controlled production code.
  • Use source control consistently.
  • Never overwrite released programs without following change control.

A Practical Program Header

/**************************************************************
Program:       t_ae_incidence.sas
Purpose:       Generate Table 14.3.1
Study:         ABC-001
Dataset:       ADAE
Output:        TLF/T14.3.1.rtf
Author:        Statistical Programming
Version:       1.3
Specification: TLF-SPEC-014
QC:            Independent QC completed
**************************************************************/

The exact format should follow the organization's programming standards.

Validation of Production Outputs

Before release, perform a final output review.

Area Question
Content Are all required statistics present?
Population Are the correct subjects included?
Calculations Do key values reconcile independently?
Labels Are titles, units, and headers correct?
Formatting Is the final presentation correct?
Traceability Can the output be traced to controlled inputs?
Version Is the released program identifiable?
Approval Has the required review been completed?

Validation vs. QC: A Practical Distinction

The exact terminology differs across organizations, but a useful practical distinction is:

V
Validation asks whether the controlled process is fit for its intended use and provides documented assurance of reliability.
Q
Quality control comprises checks used to detect errors and confirm that deliverables meet requirements.
R
Review provides qualified human assessment of the evidence and result.

These activities overlap, but they are not necessarily identical.

The Most Important Principle

The most important principle in regulated SAS programming is:

Do not try to prove that the SAS program is perfect. The goal is to establish, through a documented and risk-appropriate process, that the computerized process is suitable for its intended use and that the resulting data and outputs are reliable, traceable, controlled, and reproducible.

Final Validation Checklist

Question Validated?
Is intended use defined? ☐
Are requirements documented? ☐
Has risk been assessed? ☐
Is the program version controlled? ☐
Are input datasets controlled? ☐
Have critical derivations been independently verified? ☐
Have boundary and exceptional cases been tested? ☐
Has the SAS log been reviewed? ☐
Have outputs been reconciled? ☐
Has the final output been visually reviewed? ☐
Are discrepancies documented and resolved? ☐
Is traceability complete? ☐
Are approvals documented? ☐
Is the released version identifiable and reproducible? ☐

Summary

Validating SAS programs in a regulated environment is much broader than checking whether SAS code executes successfully.

A robust approach begins with intended use and risk, translates requirements into testable expectations, uses appropriately independent verification, examines both code and outputs, investigates discrepancies, and maintains complete traceability.

The validation process should also account for:

  • Controlled programming environments
  • Version control
  • Access management
  • Audit trails
  • Electronic records
  • Change control
  • Regression testing
  • Reusable macros and frameworks
  • Dataset and metadata validation
  • Output review
  • Inspection readiness

The strongest regulated programming organizations treat validation as part of the development lifecycle rather than as a final QC gate.

Bottom line: A validated SAS analysis should be more than a correct-looking output. It should be the product of a controlled, documented, risk-based process in which requirements, code, data, testing, review, changes, and final results can be traced and reconstructed. Independent programming, automated comparisons, targeted test cases, source-code review, and visual inspection are complementary tools—not substitutes for a coherent validation strategy.

References

U.S. Food and Drug Administration (FDA). 21 CFR Part 11 — Electronic Records; Electronic Signatures.
U.S. Food and Drug Administration (FDA). Computer Software Assurance for Production and Quality System Software. Guidance for Industry and Food and Drug Administration Staff.
U.S. Food and Drug Administration (FDA). Data Integrity and Compliance With Drug CGMP: Questions and Answers. Guidance for Industry.
International Council for Harmonisation (ICH). E6(R3) Good Clinical Practice.
International Council for Harmonisation (ICH). E8(R1) General Considerations for Clinical Studies.
ISPE. GAMP 5: A Risk-Based Approach to Compliant GxP Computerized Systems.
SAS Institute Inc. SAS® documentation and programming language reference materials.