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 ↗
← SASnRMerging datasets - cartesian product

Introduction

  • A Cartesian product (cross join) pairs every row of one dataset with every row of another, producing every possible combination.
  • In clinical programming this is handy for building summary shells: row categories crossed with treatment arms, for example.
  • SAS does this with a DATA step using two SET statements without a BY, or via PROC SQL.
  • Tidyverse provides cross_join(). Base R uses merge() with by = NULL.
  • This lesson crosses three summary row templates with four treatment arms to produce 12 combinations.
  • After running, the output dataset has rows * columns = 3 * 4 = 12 rows.

Merging datasets - cartesian product