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 ↗
← SASnRArrays-repeat same logic on multiple variables

Introduction

  • A common chore: apply the same transformation to several columns at once — strip a character from every raw date field, convert every numeric column to a character, replace a sentinel value across multiple columns.
  • Writing the logic once and looping it over a list of columns keeps the code short and easy to extend when new columns arrive.
  • SAS expresses this with the ARRAY statement inside a DATA step, plus a DO loop indexed by dim().
  • Tidyverse uses across() inside mutate(), paired with a tidyselect helper like where() or an explicit column list.
  • Base R uses lapply() over a column vector, assigning the result back to the same columns of the data frame.
  • This lesson replaces forward slashes with spaces across three raw date columns on an enrollment dataset.

Arrays-repeat same logic on multiple variables