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 ↗
← SASnRconditional logic - if_else

Introduction

  • A simple two-branch condition — if X then A, else B — is the workhorse of derived variables.
  • SAS uses if cond then var = "A"; else var = "B"; inside a DATA step.
  • Tidyverse offers if_else() from dplyr, which is strict about types. Base R uses ifelse(), which is looser about types but handles NAs differently.
  • This lesson flags subjects as 60+ or under 60 based on the age variable.
  • After running, every row has the right label in agegr1 based on its age.

conditional logic - if_else