A little announcement. A lot to explore.

Happy learning!

Explore lessons, including SAS & R programs and practice data.

Search lessons

Type at least 3 characters to see matching lessons.

Open SAS ↗Open R ↗
← SASnRRun multiple programs from a single file

Introduction

  • In clinical programming, we routinely build a deliverable by running several programs in sequence — for example, one program per SDTM domain, then one per ADaM dataset, then one TFL per table.
  • In SAS, a shared project team usually handles this through the institutional batch submission tool (SAS Grid, a shell wrapper, or a drop-folder that a scheduler watches). There is no single portable SAS file that reliably submits every other SAS file for us, which is why this lesson has no SAS variant — the equivalent step lives outside SAS itself.
  • In R, we can drive the whole batch from a single R file that calls each individual program in its own fresh R session. This gives us predictable isolation, per-program log files and an explicit execution order — all the things a SAS batch setup usually provides.
  • In this lesson we set up a tiny worked example:
    • three small R programs that each create one XPT file (DM, AE, LB),
    • one driver file run_all.R that runs the three programs in order and writes one log file per program.
  • Folder layout we assume:
    • r_batch_xpt_example/
      • run_all.R (the batch driver, at the top level)
      • programs/
        • 01_make_dm_xpt.R
        • 02_make_ae_xpt.R
        • 03_make_lb_xpt.R
      • output/xpt/ (created automatically when we run)
      • output/logs/ (created automatically when we run)
  • Each individual R program should be fully self-contained — it should read or build its own data, process it and write its output without depending on objects left behind by another program.
  • To kick off a batch run, we open a terminal in the project folder and execute Rscript run_all.R. The driver runs each program in a clean R session, captures its output to a per-program log file, and continues to the next one.
  • After the run, we expect to find DM.xpt, AE.xpt and LB.xpt under output/xpt/, plus one .log file per program under output/logs/.
  • Adding a new program is a two-step change: drop a new file like 04_make_ex_xpt.R into the programs/ folder, then add its path to the scripts vector in run_all.R.

Run multiple programs from a single file