Sample 24652: Generate every combination of observations between data sets
Create a Cartesian product between two data sets using the DATA step.
See also Sample 25270, "Using PROC SQL to generate the Cartesian Product."
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.
/* Create two test data sets */
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
;
data every_combination;
/* Set one of your data sets, usually the larger data set */
set one;
do i=1 to n;
/* For every observation in the first data set, */
/* read in each observation in the second data set */
set two point=i nobs=n;
output;
end;
run;
proc print data=every_combination;
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 b apple brown
3 b apple black
4 c apple cocoa
5 c apple cream
6 a apple amber
7 b apple brown
8 b apple black
9 c apple cocoa
10 c apple cream
11 a banana amber
12 b banana brown
13 b banana black
14 c banana cocoa
15 c banana cream
16 a coconut amber
17 b coconut brown
18 b coconut black
19 c coconut cocoa
20 c coconut cream
21 a coconut amber
22 b coconut brown
23 b coconut black
24 c coconut cocoa
25 c coconut cream
26 a coconut amber
27 b coconut brown
28 b coconut black
29 c coconut cocoa
30 c coconut cream
Type: | Sample |
Topic: | SAS Reference ==> DATA Step SAS Reference ==> Statements ==> File-handling ==> SET ==> with NOBS= Common Programming Tasks ==> Combining Data SAS Reference ==> Statements ==> File-handling ==> SET ==> with POINT=
|
Date Modified: | 2018-11-30 16:01:37 |
Date Created: | 2004-09-30 14:09:01 |
Operating System and Release Information
SAS System | Base SAS | All | n/a | n/a |