Skip to content

Dataset

R code datasets with SAS and Stata programs for AI training

An R code dataset is a collection of statistical analysis programs written in R, usually requested together with SAS programs and Stata do-files, delivered with the analysis plan or table shell each program implements, its run log and the tables, listings and figures it produced. SourceX sources these to a buyer's spec from established businesses such as contract research organizations, insurers, market research firms and economic consultancies, without the subject-level data the programs read. Each dataset is de-identified and licensed for an agreed permitted use.

Dataset manifest

Sourced to your spec
What it is
Analysis programs with the specification they implement, run logs, outputs and validation records
Typical systems
SAS, R, Stata, Git or Subversion, validated statistical computing environments, shared study folders
Typical history
Varies by partner; study archives can span years. Specify the period and language mix you need
Modality
Source code with logs, specification documents and rendered tables, listings and figures
Delivery formats
Source files (.sas, .R, .Rmd, .do) and logs as text, outputs as RTF, PDF or text, JSONL manifest
Preparation
Subject-level data left out; client, sponsor, study and product names pseudonymized; paths, usernames and credentials removed
Licensing
Scoped per study, project or macro library; permitted use agreed per license; client permissions reviewed per source
Availability
Sourced to your spec from organizations that hold the programs; supply is not guaranteed
CodeIllustrative

What a delivery contains

Fields vary by source system and are fixed per order. A typical delivery includes:

FieldTypeWhat it holds
program_idstringPseudonymous, stable ID that the log, output, specification and validation records refer to.
program_languageobjectSAS, R or Stata, with the software version printed in the run log where one exists.
program_roleenumProduction, independent validation, dataset derivation, table, listing, figure, macro or setup program.
deliverableobjectThe output the program produces, with its type, number and title as given in the shell.
specobjectThe analysis plan section, table shell and variable derivations the program implements, each with its version.
sourcestringFull program text with header block and comments, encoding and line endings as archived.
inputsarrayDatasets and variables the program reads, by name, type and label, with no data values.
called_codeobjectMacros, setup programs, format catalogs, R packages or Stata ado-files called, with versions where recorded.
run_logobjectLog of the archived run with timestamp, error and warning counts and flagged notes.
outputobjectThe rendered table, listing or figure with titles and footnotes, limited to aggregate results.
validationobjectIndependent programming, code review or manual check, the counterpart program and each comparison round.
revisionsarrayVersion control or archive history with timestamps, author roles and reasons for change.
study_contextobjectPseudonymous study or project, its design and whether the run was a dry run, interim or final.
data_shippedenumNone, structure-only metadata or synthetic data built to the input structure.
Sample recordIllustrative

Field names from the table above; values are masked placeholders.

Example record

{
  "program_id": "prg_7c41e9",
  "program_language": {
    "name": "sas",
    "version_in_log": "[VERSION]"
  },
  "program_role": "production",
  "deliverable": {
    "type": "table",
    "number": "Table 14.2.1.1",
    "title": "Change from Baseline in [ENDPOINT] at Week 12, ANCOVA (Full Analysis Set)"
  },
  "spec": {
    "plan_ref": "SAP v2.0, section 9.2.1",
    "shell_ref": "TLF shells v3, T14.2.1.1",
    "derivation_refs": [
      "ADEFF.CHG",
      "ADEFF.ANL01FL"
    ]
  },
  "source": "/* t_14_2_1_1.sas | Shell: T14.2.1.1 v3 | SAP 9.2.1 */\n%m_popn(in=adeff, pop=fasfl, out=eff);\nproc mixed data=eff;\n  where paramcd='PRIM' and avisitn=12 and anl01fl='Y';\n  class trt01pn;\n  model chg = trt01pn base;\n  lsmeans trt01pn / diff cl;\n  ods output diffs=lsdiff;\nrun;\n%m_rtfout(data=lsdiff, shell=T14_2_1_1);",
  "inputs": [
    {
      "dataset": "ADSL",
      "variables": [
        "USUBJID",
        "TRT01PN",
        "FASFL"
      ]
    },
    {
      "dataset": "ADEFF",
      "variables": [
        "USUBJID",
        "PARAMCD",
        "AVISITN",
        "BASE",
        "CHG",
        "ANL01FL"
      ]
    }
  ],
  "called_code": {
    "macros": [
      "%m_popn",
      "%m_rtfout"
    ],
    "setup": "setup.sas"
  },
  "run_log": {
    "run_at": "2023-05-16T14:02:11Z",
    "errors": 0,
    "warnings": 0,
    "flagged_notes": [
      "NOTE: Missing values were generated as a result of performing an operation on missing values."
    ]
  },
  "output": {
    "file": "t_14_2_1_1.rtf",
    "content": "aggregates only"
  },
  "validation": {
    "method": "independent_programming",
    "counterpart_program_id": "prg_b20d55",
    "counterpart_language": "r",
    "compare_tool": "PROC COMPARE",
    "rounds": [
      {
        "n": 1,
        "result": "3 observations with unequal values for the treatment difference",
        "cause": "visit window footnote read two ways",
        "fix": "shell clarified in v3"
      },
      {
        "n": 2,
        "result": "no unequal values found, all values compared exactly equal"
      }
    ]
  },
  "revisions": [
    {
      "rev": 2,
      "t": "2023-05-16T13:40:00Z",
      "summary": "Updated to shell v3 after QC round 1"
    }
  ],
  "study_context": {
    "study": "STUDY-0412",
    "design": "randomized, parallel group",
    "analysis": "final"
  },
  "data_shipped": "none"
}

Synthetic record for illustration. Field names, structure and format are agreed per order.

What AI teams use it for

Write analysis code from a specification

Plan sections and table shells paired with the accepted program train a model to turn a written statistical requirement into working SAS, R or Stata.

Translate between SAS and R

Outputs programmed in SAS on one side and R on the other give aligned pairs that produce the same numbers, which migration tools need.

Train code reviewers on real discrepancies

Failed comparison rounds, with the fix that followed, are worked examples of finding which of two programs is wrong.

Read and triage run logs

Logs with the notes a reviewer flagged, such as uninitialized variables or a merge with repeated key values, teach which messages change results.

Build graded evaluation items

A held-out shell with its validated output is a test item with a known answer, scored on numbers and layout.

Use-case guides: Coding agents, Private evaluation sets, Document AI, enterprise search and RAG

What makes this data valuable

Specification linkage

Each program names the plan section and shell version it implements, so requirement, code and output join without guessing.

Independent validation pairs

Production and validation programs for the same output are both delivered, with the comparison between them.

Mismatch history

Early comparison rounds and their resolutions are kept, not only the final clean run.

Complete logs

Each program has the log of its archived run, with no unexplained errors or warnings.

Closed dependencies

Macros, setup programs, formats and package versions are delivered or listed as excluded.

No data in code or logs

A documented scan shows no hard-coded subject IDs, printed records or individual listings.

Process

R code dataset

This page covers statistical analysis code in R, SAS and Stata.Illustrative

Each program answers a written specification

Statistical programs in contract and regulated work are written to a document, and that document can be delivered with them. In a clinical study the statistical analysis plan sets the analysis populations, endpoints, models and the handling of missing data, and is normally finalized before the data is unblinded. Table shells then mock up every table, listing and figure with its exact rows, columns, decimal places, titles and footnotes, and a dataset specification gives the derivation of each analysis variable. Each program therefore has three parts: a stated requirement, usually named in its header, the code, and the output that was checked against the requirement.

Public R and SAS code rarely has this. Packages, course exercises and forum answers show how a function is called, but not what the author was asked to produce or whether the result was accepted. In an exploratory notebook the question shifts as the analyst works. Here the requirement was fixed first, so a model can be trained to write the program from the plan and shell, and graded on whether its output matches the validated one cell for cell.

Three things weaken the pairing. Plans are amended and shells are reissued, so a program must be tied to the version it was written against, not the final one. Shells are often Word files with tracked changes that flatten badly to text. Outside clinical research the specification is looser: a tabulation spec at a market research firm, a methods memo behind an expert report, an email from an actuary. Ask what share of programs link to a specification, and of which kind.

Double programming leaves two answers and a comparison

In regulated statistical work, key analysis datasets and outputs are commonly programmed twice. A second programmer works from the same specification without reading the production code, and the two results are then compared electronically: PROC COMPARE in SAS, a data frame comparison such as diffdf in R, or the cf command in Stata. The archive therefore holds two independent implementations of one requirement, often in different styles, a DATA step merge on one side and PROC SQL on the other, and sometimes in different languages, with comparison output stating whether every value matched.

That is verification data that is hard to find elsewhere. A clean comparison is evidence that both programs are right. A failed one is more useful: it shows which observations and variables differed, and the next revision shows who changed what. Many early mismatches trace back to the specification, where two careful readers took a derivation rule differently and the fix was a clarified shell or plan. Models that review code have few real examples of this.

Check how much of it survived. Holders often keep only the final clean comparison, with the early mismatches left in email or an issue tracker. Not every output is double-programmed. Under risk-based validation, listings and lower-risk tables may get a code review or a manual check against the shell instead. Comparisons also carry settings, such as key variables and a numeric tolerance, that decide what counts as a match. Ask for the validation method per output and the comparison options used.

What to check before licensing

  • Search sample programs and logs for subject-level data: hard-coded subject IDs in data fixes, records printed to the log, and listings, which are individual data by design.
  • Ask who owns each program. Code written for a sponsor or client often needs that party's permission, so ask how permission was established per study or project.
  • Request the validation method per output, count how many have an independent second program, and confirm both sides and the comparison output are delivered.
  • Check that each program is tied to the plan and shell version it was written against, and that amendments and reissued shells are included.
  • Trace dependencies on a sample. Every macro, format catalog, R package and user-written Stata command should be delivered or named as excluded, including third-party macro libraries.
  • Ask whether outputs hold unpublished or unblinded results and how small cell counts were handled. For clinical studies, have counsel confirm the approach.
  • Decide whether you need code that executes. If so, ask whether synthetic data built to the input structure can be supplied.

Delivery No files move before a signed license. A listing or a request grants no files by itself.

How licensing works through SourceX

  1. 1

    Define

    Send the domain, modality, volume, format, timeline and permitted use you need.

  2. 2

    Source

    SourceX identifies businesses that hold matching data and are open to licensing it.

  3. 3

    Qualify

    Fit, rights and quality are checked, and you review samples before committing.

  4. 4

    License

    Scope, permitted use, exclusivity, price and obligations are agreed in writing.

  5. 5

    Deliver

    Approved data is prepared, de-identified where required and transferred securely.

Questions Acquisition Partners ask

Does the dataset include the data the programs were run on?

No, not the real data. The dataset is scoped to programs, logs and outputs, without the subject-level or record-level data the programs read, which concerns study participants, policyholders or survey respondents. Input datasets are described by structure: dataset names, variables, types and labels. Check a sample for values that leaked into logs and listings. If you need programs that execute, ask whether the holder can supply synthetic data built to that structure.

What is double programming and how much of the code has it?

Double programming means a second programmer writes the same dataset or output independently from the specification, and the two results are compared electronically. It is common practice for analysis datasets and primary outputs in regulated clinical work, and less common for listings and commercial analytics, where code review is typical. Coverage differs by holder and by study, so ask for the validation method recorded against each output.

Which languages and packages does the code use?

SAS, R and Stata, in proportions that depend on the holder. Older clinical archives are mostly SAS, with heavy use of the macro language, PROC SQL and the statistical procedures. Newer work adds R, often with tidyverse and open-source clinical reporting packages, and economic consultancies rely on Stata do-files with user-written commands. State the language mix and period you want.

Can the programs be re-run after delivery?

Not as delivered, because the input data stays with the holder. Each program's behavior is documented by its run log and output instead. To execute the code you need data with the same structure, the macros, formats and setup programs it calls, and a matching software version. Ask which of these the holder can supply.

Is this only clinical trial code?

No. Clinical programming is the most formally specified source, but insurers hold experience studies and pricing analyses, market research firms hold weighting and tabulation programs, and economic consultancies hold the code behind expert reports. These follow looser specifications and lighter validation, and cover methods clinical code rarely uses, such as survey weights, panel regressions and generalized linear models for claims.

Who has to agree before the programs can be licensed?

The holder, and in most contract work the client as well. Programs written for a sponsor under a services agreement are often the sponsor's property or covered by its confidentiality terms, while a research organization's own macro library usually is not. Ask how permission was established for the sources in your sample, and have counsel confirm it covers your intended use.

Evaluating this data for procurement?

Diligence packets are prepared per dataset. Rights, privacy processing and quality differ between datasets.

Request dataset diligence

Tell us what your models need

Send your spec — domain, volume, format, timeline and permitted use — and SourceX will match it against partner data and come back with what can be licensed.

Updated 25 November 2026.

See if your company qualifies