STRIP | trimws

Character Functions
Overview

Removes leading and trailing white spaces from character strings.

⚠ Behavior Difference

Behavior is the same. Both remove leading and trailing spaces only.

Syntax Comparison
SAS
SAS
strip(var)
R
R
trimws(var)
Details

Good practice to apply to character variables before comparison or merge to avoid formatting inconsistencies.

ExampleCode
SAS Example
SAS
data dm;
  input USUBJID $ SITEID $;
datalines;
101-001    001
;
run;

data dm2;
  set dm;
  SITEID_CLEAN = strip(SITEID);
run;
R Example
R
library(dplyr)

dm <- data.frame(
  USUBJID="101-001",
  SITEID=" 001 "
)

dm <- dm %>%
  mutate(SITEID_CLEAN = trimws(SITEID))
Output Dataset

USUBJID   SITEID   SITEID_CLEAN
101-001   001      001