Sample 24652: Generate every combination of observations between data sets
Create a cartesian product between two data sets using the DATA
step instead of
PROC SQL. No common variable is required.
/* 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;
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
Create a cartesian product between two data sets using the DATA step instead of
PROC SQL. No common variable is required.
| 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: | 2009-02-27 11:39:34 |
| Date Created: | 2004-09-30 14:09:01 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |