sap-writer¶
Draft a statistical analysis plan from a protocol and its estimands under ICH E9 and E9(R1), covering analysis sets, estimand handling, primary and sensitivity analyses, multiplicity, missing data, interim analyses and planned TLFs, then check structure and estimands.
| Stage | Clinical development |
| Tier | 2 (template and rubric) |
| Standards | ICH E9, ICH E9(R1), ICH E3, ICH M11 |
Minimum pharmaskills |
0.4.0 |
| Inputs | protocol, estimands, sample size |
| Outputs | sap docx, sap md, structure report json, estimand check json |
| Verified by | docs check-structure, protocol check-estimands, docs build |
Draft for qualified review. Not a validated system and not 21 CFR Part 11 compliant.
Install only this skill: pharmaskills skills install --agent claude-code --skill sap-writer (see Install).
Purpose¶
Turn a protocol with its estimands into a statistical analysis plan a biostatistician can review
and finalise before unblinding: each analysis traces to an estimand and to a protocol section,
sets and conventions are explicit, missing data are handled per intercurrent event, multiplicity
and interim analyses are stated, and the planned tables are numbered so tlf-shells can build
shells from them.
When to use / when not to use¶
Use after the protocol is drafted (see protocol-m11) and before database lock, to produce
sap.docx, or to restructure an existing SAP against ICH E9 and E9(R1) topics.
Do not use for: choosing or changing analyses after unblinding, Bayesian or adaptive design
specifications, statistical programming or numerical results, or sample size (use sample-size).
Never decide a strategy the protocol leaves open: it becomes a [DATA NEEDED] item for the
statistician.
Inputs¶
Required: the protocol (Markdown, DOCX or YAML) with a five-attribute estimand for each primary
endpoint, the sample size result, and the analysis conventions the sponsor uses. Ask once,
in a single message, for what is missing, then proceed with stated assumptions and
[DATA NEEDED: ...] placeholders (for example software version, MedDRA version, the
multiplicity decision if the protocol is silent). State the region assumed (default US with
FDA expectations; the ICH E9 content is region independent).
If pharmaskills is not installed, say so (uv tool install pharmaskills), draft from
templates/sap.md, and mark the structure and estimand checks as not run. Check
pharmaskills --version is at least min_pharmaskills.
Workflow¶
- Check the protocol.
pharmaskills protocol check-estimands PROTOCOL --out out/protocol_estimand_check.json. Exit 2: stop sections 4, 7 and 10, writeout/estimand_gap_note.mdlisting the gaps, and continue with the other sections. - Map estimand to analysis with
references/estimand-to-analysis.md: one primary analysis per primary estimand, one row per intercurrent event in sections 4.1 and 10. - Write
out/sap.mdfromtemplates/sap.md(headings numbered 1 to 18 as in the standardsap). Primary endpoint headings use the protocol wording so the estimand checker matches. Sensitivity analyses vary one stated assumption (references/e9-topics.md). Multiplicity followsreferences/multiplicity-and-interim.md; with more than one primary endpoint section 11 must state the rule for the family. - Planned TLFs in section 16 as
Table 14.n.n Title (population)lines (also Listing 16.n.n, Figure 14.n.n).tlf-shellsreads them. - Build.
pharmaskills docs build out/sap.md --out out/sap.docx --title "..." --skill sap-writer, thenpharmaskills docs banner --apply out/sap.md(draft banner, provenance). - Verify.
pharmaskills docs check-structure out/sap.docx --standard sap --out out/structure_report.jsonandpharmaskills protocol check-estimands out/sap.docx --out out/estimand_check.json; both must exit 0. - Report analyses planned, open decisions and every
[DATA NEEDED].
Output contract¶
Under out/:
| File | Content |
|---|---|
sap.docx, sap.md |
The SAP with banner and provenance, numbered sections 1 to 18 |
structure_report.json |
docs check-structure --standard sap report |
estimand_check.json |
protocol check-estimands report on the SAP |
estimand_gap_note.md |
Only when the protocol lacks estimand attributes |
Verification¶
Report pass or fail: structure check exit 0 with no missing required section; estimand check exit 0 on protocol and SAP; the sample size in section 15 equals the tool output the protocol cites; each intercurrent event of the estimand appears in sections 4.1 and 10; section 11 is explicit; interim analyses are stated even if "none"; planned tables are uniquely numbered; the draft banner is present. Statistical appropriateness stays a documented review item.
Guardrails¶
- Insert the draft banner and a provenance block; a biostatistician must approve the SAP.
- Never choose strategies the protocol leaves open, invent effect sizes, results or p-values, or back-date a SAP. A SAP changed after unblinding is a documented post-hoc change, not a SAP.
- Never fabricate citations; cite ICH E9 and E9(R1) by identifier and section, flagged where unsure.
- Do not compute statistics here; computation belongs to validated programs.
- State the region assumed and that regional authority expectations are not covered.
References¶
references/e9-topics.md- SAP sections mapped to ICH E9 and E9(R1)references/estimand-to-analysis.md- strategies to handlingreferences/multiplicity-and-interim.md- multiplicity and interim rules- Public sources: ICH E9 (sections 2.2, 3.5, 4.5, 5.1 to 5.9, 6), ICH E9(R1), ICH E3 section 14.
Templates: templates/sap.md. Scripts: scripts/check_sap.sh.
Examples¶
Worked example: examples/clinical/sap-writer/ (single primary and two co-primary SAPs, estimand
gap note, refusal). Cases: skills/sap-writer/evals/cases/.
Worked example¶
Committed example with inputs and outputs: examples/clinical/sap-writer/.
SAP for the synthetic protocol PSK-201-DM2-01 (the protocol-m11 worked example).
Inputs¶
skills/sap-writer/evals/fixtures/protocol.md (copy of examples/clinical/protocol-m11/out/protocol.md)
and protocol_no_estimand.md (incomplete protocol for the edge case).
Outputs (out/)¶
| File | How it was made |
|---|---|
sap.md, sap.docx |
Drafted from the protocol following templates/sap.md, built with pharmaskills docs build |
sap_two_primary.md, .docx |
Variant with two co-primary endpoints and an intersection-union multiplicity rule |
structure_report.json |
pharmaskills docs check-structure sap.docx --standard sap |
estimand_check.json, estimand_check_two_primary.json |
pharmaskills protocol check-estimands on the SAPs |
estimand_gap_note.md, refusal_post_hoc_sap.md |
Sample correct responses |
All numbers (86 and 102 per arm, alpha 0.05, 12 weeks) come from the protocol.
Reproduce¶
pharmaskills docs check-structure out/sap.docx --standard sap
pharmaskills protocol check-estimands out/sap.docx
Skill source: skills/sap-writer/SKILL.md