I have two single column data sets with unique variables. I'd like to merge them to create a 2 column data set with an observation for every pair of variables from the the two original data sets. See example below.
I have the below two data sets with 1 column each:
| cat1 |
| a |
| b |
| c |
| d |
| e |
| cat2 |
| 1 |
| 2 |
| 3 |
| 4 |
I want the below data set:
| cat1 | cat2 |
| a | 1 |
| a | 2 |
| a | 3 |
| a | 4 |
| b | 1 |
| b | 2 |
| b | 3 |
| b | 4 |
| c | 1 |
| c | 2 |
| etc... | etc... |
data one;
input cat1 $;
cards;
a
b
c
d
e
;
data two;
input cat2 ;
cards;
1
2
3
4
;
proc sql;
create table want as
select cat1, cat2
from one , two
order by cat1,cat2;
quit;
data one;
input cat1 $;
cards;
a
b
c
d
e
;
data two;
input cat2 ;
cards;
1
2
3
4
;
proc sql;
create table want as
select cat1, cat2
from one , two
order by cat1,cat2;
quit;
Cartesian join in SQL:
proc sql;
create table want as
select
ds1.cat1,
ds2.cat2
from ds1, ds2
;
quit;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.