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 ↗
← SASnRDefine and Call a Macro with Parameters

Introduction

  • Clinical programs repeat the same logic for different treatment groups, variables, or datasets β€” a reusable macro (SAS) or function (R) avoids copy-paste and keeps code maintainable.
  • We define a block of logic once, give it parameters for the parts that change, and call it with different arguments each time.
  • SAS uses %MACRO / %MEND with keyword parameters and optional defaults. R uses function() with named arguments and optional defaults.
  • This lesson builds a small utility that subsets an ADSL-like dataset by treatment group and calculates mean age β€” the kind of reusable helper every clinical program benefits from.
  • After running, we check that each call produces the correct subset and summary for the requested treatment arm.

Define and Call a Macro with Parameters