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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.