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 ↗
← SASnRAdding new variables

Introduction

  • Most analysis steps derive new variables from existing ones — BMI from height and weight, age bands from age, or a flag from a date comparison.
  • SAS does this inside a DATA step by assigning to a variable that does not yet exist. The new name appears as a column in the output.
  • In tidyverse we use mutate(), which adds one or more derived columns in a single call. In base R we assign to df$new_col directly.
  • This lesson derives BMI (weight in kg divided by height in metres squared) from the CLASS dataset. Height in the input is inches, weight is pounds, so we convert units in the formula too.
  • After running, the new column BMI holds a numeric BMI value for each subject.

Adding new variables