StatAgent

Translate SAS to R with AI, then prove the numbers match

The biggest trap with AI-translated code is that it runs but gives different numbers. This workflow forces a proof.

Facts on this page are checked against the sources linked here. The prompt has not yet been run on a live assistant. How we check.

Step 1: Translate

Translate the SAS program below to R. Prefer tidyverse and, where relevant,
pharmaverse packages. Rules:
1. Preserve logic exactly. Do not "improve" it.
2. Add a comment above any line where SAS and R behave differently
   (missing values, sorting, rounding, merge/join semantics, formats,
   PROC MEANS defaults, PROC FREQ denominators).
3. List every assumption at the end.

SAS CODE:
[paste code - use public or simulated data only]

Step 2: Make the AI list the gotchas

List the 10 most common SAS-to-R discrepancies that would affect THIS program
and tell me exactly how to test for each one.

Typical findings, with the specifics worth knowing:

Step 3: Prove it

Run both programs on the same public dataset and compare. Good free sources are the original CDISC pilot data in the phuse-org/phuse-scripts GitHub repository (see the repository: SDTM is under data/sdtm/cdiscpilot01, ADaM under data/adam/cdisc, and there are also updated pilot sets; folder layouts can change) and the pharmaverse R packages pharmaversesdtm and pharmaverseadam, which ship SDTM and ADaM test data built from the pilot study. Then compare:

Write R code that compares my SAS output (exported to CSV) with my R output
and reports every difference with variable, row, and magnitude.
Rule: never accept a translation until the comparison shows zero unexplained differences.

Get the next workflow by email →