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 ↗
← SASnRRemove objects from the environment (rm / remove)

Introduction

  • When experimenting, we often want to remove temporary objects from the environment to avoid name clashes and stale values
  • ls() (or objects()) lists what is currently in the environment
  • rm(x) removes a single object; rm(a, b) removes multiple
  • For scripts, prefer rm(list = ...) where the list is built programmatically
  • Common patterns
    • Keep only a few: rm(list = setdiff(ls(), c("adsl","adlb")))
    • Remove by pattern: rm(list = ls(pattern = "^tmp_"))
    • Clear all (use with care): rm(list = ls())
  • Think of this like cleaning the SAS WORK library between steps—keeps our workspace predictable while we iterate