Sample 25284: Using PROC SQL to create the cartesian product between matching key values
The SQL procedure creates all possible combinations when joining tables, unless a WHERE clause is specified.
The sample code on the Full Code tab is the alternative method referenced in
Sample 24752, "Perform a many-to-many merge based on common variables".
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
data one;
input id $ fruit $;
datalines;
a apple
a apple
b banana
c coconut
c coconut
c coconut
;
data two;
input id $ color $;
datalines;
a amber
b brown
b black
c cocoa
c cream
;
proc sql;
create table both as
select one.id
,one.fruit
,two.color
from one
,two
where one.id = two.id;
quit;
proc print data=both;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Obs id fruit color
1 a apple amber
2 a apple amber
3 b banana brown
4 b banana black
5 c coconut cocoa
6 c coconut cream
7 c coconut cocoa
8 c coconut cream
9 c coconut cocoa
10 c coconut cream
This example illustrates the creation of the cartesian product between matching keys. This is an alternative method to performing a many-to-many merge based on common variables.
Type: | Sample |
Topic: | SAS Reference ==> Procedures ==> SQL
|
Date Modified: | 2005-06-01 11:39:52 |
Date Created: | 2005-04-22 15:42:32 |
Operating System and Release Information
SAS System | Base SAS | All | n/a | n/a |