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

Goal

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.

          TRIAL_A

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

       TRIAL_TESTS

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

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.