BookmarkSubscribeRSS Feed
Babloo
Rhodochrosite | Level 12

I need to join three tables but there is no common variable for first table. There is one common variable called 'bipad' between second and third table. 

 

I need to join three tables as like below code without any condition. How to achive it?

 

Code below is throwing errors.

 

proc sql;
select WH_NO,WH_NAME,CITY_NAME,STATE_ALPHA  from MASSH.ACCOUNT
union
select sum(copies) as totalcopies from EMS.TBK_WS_DRAW_SALE_TRANSACTION where bipad in (10227,32686)
union
select ISSUE_NAME,ISSUE_NO,ONSALE_DATE,OFFSALE_DATE from MASSH.ISSUE where bipad in (10227,32686) and (ISSUE_YEAR=2015);
quit;
5 REPLIES 5
Steelers_In_DC
Barite | Level 11

You should give an example of the data you have.  An another example of what you want your output to look like.  The way you have it written isn't correct and it's hard to guess what you are trying to do.

saspert
Pyrite | Level 9

Why are you not including bipad variable in the select clause? Just wondering if you were trying to append or merge the 3 tables? 

SASKiwi
PROC Star

A standard UNION is not going to work because there are no common variables in any of your select statements. Only an OUTER UNION will allow you to join columns with different names.

Babloo
Rhodochrosite | Level 12

I would like to append the result of all the three queries via proc sql.

 

select WH_NO,WH_NAME,CITY_NAME,STATE_ALPHA  from MASSH.ACCOUNT;

 

This query has result like follows    

 

WH_NOWH_NAMECITY_NAMESTATE_ALPHA
10029KABLE SPEC/DEYCO/W.TOWNSHWALL TOWNSHINJ

 

select sum(copies) as totalcopies from EMS.TBK_WS_DRAW_SALE_TRANSACTION where bipad in (10227,32686);

 

This query has result like follows  

 

TOTALCOPIES
88658065

 

select ISSUE_NAME,ISSUE_NO,ONSALE_DATE,OFFSALE_DATE from MASSH.ISSUE where bipad in (10227,32686) and (ISSUE_YEAR=2015);

 

This query has result like follows 

    

ISSUE_NAMEISSUE_NOONSALE_DATEOFFSALE_DATE
6/152405-JUN-1519-JUN-15

 

Now I need to combine the result of all the three queries. Please guide me

Kurt_Bremser
Super User

If you want a dataset with only one record and all the variables, create three intermediate tables and use a MERGE without BY to create the wanted result.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 8482 views
  • 0 likes
  • 5 in conversation