Traps: dplyr::if_else() is stricter on types than base ifelse(). Prefer if_else() in dplyr pipelines. case_when() stops at the first true condition. Older dplyr used TRUE ~ instead of .default. SAS ifc(age < 65, "<65", ">=65") puts missing age in "<65"; R if_else() returns NA.
Worked examples below.
Two-way: if_else()
library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
USUBJID AGE AGEGR1
1 STD-001-0001 54 <65
2 STD-001-0002 70 >=65
3 STD-001-0003 NA <NA>
When AGE is NA, if_else() returns NA for that row (unless you set missing=).
SAS ifc(age < 65, "<65", ">=65") is not the same on missing age. Missing is smaller than any number, so the condition is true and SAS returns "<65". R returns NA.