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 ↗
← SASnRKeep Only Variables with Non-missing Values Across Dataset

Introduction

  • In real clinical data, some expected columns are never collected — every row is missing for them.
  • A useful clean-up pass: drop any column whose values are entirely missing across the dataset, keeping only columns that carry at least one real observation.
  • SAS does this by walking the _character_ and _numeric_ arrays, collecting variable names with at least one non-missing value, and passing that list to a KEEP= option via call symputx.
  • Tidyverse uses select(where(...)) with a predicate that returns TRUE when any value in the column is non-missing.
  • Base R uses sapply() to build a column-level logical mask, then subsets the data frame with that mask.
  • This lesson cleans up a lab dataset where ldh and crp are fully missing, dropping those two columns from the result.

Keep Only Variables with Non-missing Values Across Dataset