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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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