StatAgentWeekly email

Translate SAS to R through a reviewed design document instead of line by line

AI first writes a plain-language design document from the SAS program, a human reviews it, then AI writes R from the document. A Merck paper reports less rework than direct translation on its own unspecified cases.

Reported in literatureHigh risk

Task
Programming
Roles
Programmer, Statistician
Assistants
Microsoft 365 Copilot, ChatGPT, Claude
Last reviewed

Evidence

Reported in literature. PharmaSUG 2026 AI-305 reports averages over unspecified cases: 3 vs 2 rounds, manual revision of 55.2% of lines (direct) vs 38.4% (design-first), agreement with SAS 64.5% vs 80.3%. Case count and model are not stated. The one worked example was a simple macro with broadly similar results. Authors call for broader testing. Conference paper.

Steps

  1. Ask AI for a design document from the SAS code.
  2. Review ordering, joins, missing-value and dedup rules.
  3. Correct the document.
  4. Ask for R code from the document only.
  5. Compare R output with SAS output.

Prompt

This is the prompt, typed out. No assistant reply is shown.

You
Create a structured design document for the SAS program below: purpose and scope; input datasets, key variables and formats; preconditions such as sort order and uniqueness; outputs with structure and sort keys; ordered transformation steps; explicit ordering rules (baseline, last value, ties, windows); join keys and cardinality; handling of duplicates and non-matches; missing-value behaviour. Use plain language. List open questions where the code is unclear. Do not write R. SAS CODE: [paste code - public or simulated only] (Second message, after you review the document: Using only the reviewed design document, generate R code. List assumptions.)

Verify before you use it

How it fails

A wrong assumption in the reviewed document is carried faithfully into the R code.

Data rule: No production SAS code with study identifiers, confidential derivations or real data. Use public or simulated programs.

Sources

Related

How we check. Back to the directory.