Help using Base SAS procedures

Proc sql join without common variables

Reply
Super Contributor
Posts: 426

Proc sql join without common variables

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;
Valued Guide
Posts: 858

Re: Proc sql join without common variables

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.

Super Contributor
Posts: 275

Re: Proc sql join without common variables

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

Super User
Posts: 3,180

Re: Proc sql join without common variables

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.

Super Contributor
Posts: 426

Re: Proc sql join without common variables

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

Super User
Posts: 7,099

Re: Proc sql join without common variables

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 5 replies
  • 400 views
  • 0 likes
  • 5 in conversation