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 ↗
← SASnRSubset variables

Introduction

  • When a dataset has many columns and we only need a few, we select just those variables — the column-wise counterpart of row filtering.
  • SAS offers keep to pick variables and drop to remove them. Both support name lists and colon-prefix patterns like h: for “every variable starting with h”.
  • In R, tidyverse uses select() with a rich mini-language: bare names, negative names, starts_with(), ends_with() and friends. Base R uses [, cols] subscripting with names or name patterns.
  • This lesson shows four common variable-subset tasks on the CLASS dataset: keep specific columns, drop specific columns, drop by prefix pattern, drop by suffix pattern.
  • After running, we have multiple subset datasets with only the chosen columns.

Subset variables