Hi. I have a table with categories that I need to merge into another table table. Unfortunately for me, there are no common columns to merge by. Can this be done? I need each row (from table1) to merge with every row in my second table. Does anyone have suggestions on how I may do this? I have over 10,000 rows from my first table that I must add from table 2. Here are a few records and an example of my expected output: Thank you for any help!
Table 1 | |
ID | GEO |
22454 | C56 |
845880 | C37 |
842387 | C19 |
Table 2 |
PID_Item |
LEF |
FEH |
PHE |
MOH |
Output: | ||
ID | GEO | PID_Item |
22454 | C56 | LEF |
22454 | C56 | FEH |
22454 | C56 | PHE |
22454 | C56 | MOH |
845880 | C37 | LEF |
845880 | C37 | FEH |
845880 | C37 | PHE |
845880 | C37 | MOH |
842387 | C19 | LEF |
842387 | C19 | FEH |
842387 | C19 | PHE |
842387 | C19 | MOH |
I concur with @PaigeMiller
You just need an extra ORDER BY for the grouped results-
proc sql;
create table want as
select a.*, pid_item
from one a, two
order by id;
quit;
I need each row (from table1) to merge with every row in my second table.
This is called a Cartesian Join, and can be done in PROC SQL as follows:
proc sql;
create table want as select * from table1,table2;
quit;
I concur with @PaigeMiller
You just need an extra ORDER BY for the grouped results-
proc sql;
create table want as
select a.*, pid_item
from one a, two
order by id;
quit;
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.