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-2024.png

 

Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.

 

Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 

 

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.

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
  • 463 views
  • 2 likes
  • 3 in conversation