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 ↗
← SASnRCreate a macro variable and use it in open code

Introduction

  • Programs often need a reusable scalar — a treatment label to filter on, a study cut-off date, a current version string — that may change between runs.
  • The pattern is: define the value once at the top and reference it wherever it is needed.
  • SAS has a dedicated macro namespace: %let defines a macro variable and &name. references it.
  • R has no macro layer — a plain variable in the environment serves the same purpose, referenced by its bare name.
  • In dplyr, column names and environment variables are disambiguated automatically, so referencing the filter value is as simple as writing its name.
  • This lesson filters an ADSL sample down to subjects on the Placebo arm, showing the same parameterised pattern in SAS, tidyverse, and base R.

Create a macro variable and use it in open code