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 ↗
← SASnRLoop Inside a Macro

Introduction

  • Clinical programs often need to repeat the same logic for a list of items — generate a summary for each PARAMCD, apply a transformation to each dataset, or produce a table for each visit.
  • SAS handles this with %DO loops and %SCAN inside a macro. R uses for loops, lapply(), or purrr’s map() family.
  • This lesson shows two common patterns: looping over a numbered counter, and looping over a space-delimited list of values.
  • We use a small ADLB-like dataset and produce a mean summary for each PARAMCD — the kind of loop that drives many TFL programs.
  • After running, we confirm that one summary block is produced for each parameter in the list.

Loop Inside a Macro