BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SannaSanna
Quartz | Level 8

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

 

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

 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;

 

 

--
Paige Miller
novinosrin
Tourmaline | Level 20

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;

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 876 views
  • 2 likes
  • 3 in conversation