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 ↗
← SASnRReplicating the concept of usage of loops for dummy data creation

Introduction

  • A recurring need in early prototyping: build a skeleton dataset covering every combination of a few values — treatments x visits, groups x timepoints, subjects x parameters.
  • We want every pair to appear exactly once, so we can attach real data later without worrying about missing cells.
  • SAS builds this with nested DO loops and an OUTPUT statement, writing one row per iteration of the inner loop.
  • Tidyverse uses crossing() from tidyr, a one-liner that returns every combination of the supplied vectors.
  • Base R uses expand.grid(), the classic base-R way of producing a full-factorial data frame.
  • This lesson builds a 3 x 4 grid of treatments (1, 3, 5) and visits (0, 1, 2, 8) — 12 rows with every pair present once.

Replicating the concept of usage of loops for dummy data creation