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 ↗
← SASnRMimicking the behavior of PROC CONTENTS

Introduction

\r\n
  • In SAS, PROC CONTENTS is the go-to tool for describing a dataset — it returns a metadata listing with variable name, position, type, length and dataset-level facts like the number of observations.
  • We use it to audit newly-received data, compare structure between production and QC, and document expected variables against a spec.
  • R does not ship with a single function that returns the same shape. Between str(), names(), class(), sapply() and nrow(), the raw material is all there — but we have to assemble it ourselves when we want a clean, tabular result similar to PROC CONTENTS out=.
  • In this lesson we write a small helper function that takes a data frame and returns a one-row-per-variable tibble (or data frame) with columns: memname, name, varnum, type, length, nobs.
  • We build the helper twice — once in tidyverse and once in base R — and compare the output against the real PROC CONTENTS result from SAS.
  • After running, we confirm the R output has one row per variable in the input data frame, with the expected variable names in name and a sensible value in type (character, numeric, etc.).

Mimicking the behavior of PROC CONTENTS