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 to store list of values and use it in open code

Introduction

  • Many programs need to filter by a list of values rather than a single one — an IN-list of ages, a set of visit numbers, a handful of preferred terms.
  • The pattern extends the single-value case: define the list once, reference it in the filter clause.
  • SAS stores the list as a macro variable with %let, using %str() to protect commas from the macro processor.
  • R stores the list as an ordinary vector (c(59, 72)) and uses the %in% operator to test membership in either tidyverse or base dialects.
  • No macro quoting is needed in R because there is no macro processor to route characters through — a vector is just a vector.
  • This lesson filters an ADSL sample to rows whose age is 59 or 72, showing the same pattern in each language.

Create a macro variable to store list of values and use it in open code