Example 3.9 Generating Every Combination of Rows (Cartesian Product) between Tables


Combine two tables that have no common columns in order to produce every possible combination of rows.

Example Features

Featured StepPROC SQL
Featured Step Options and StatementsCartesian product
Related TechniqueDATA step, multiple SET statements, NOBS= and POINT= options

Input Tables

Table TRIAL_A has the identifiers for a group of patients who are participating in a clinical trial. Table TRIAL_TESTS contains the lab tests for this trial. There are no columns in common between the two tables.


Obs  patientid  patientinits
 1     KPGY         AHB
 2     MWGM         DOH
 3     PQZU         LRH
 4     FQ82         HCI
 5     EYPS         MEF


Obs  testcode  testtype 1 L001 Cholesterol 2 L002 Glucose 3 ...

Get Combining and Modifying SAS® Data Sets: Examples Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.