BookmarkSubscribeRSS Feed
SASdevAnneMarie
Barite | Level 11

Hello Experts,

 

I would like replace the set of two tables by proc sql. Do I need to write full join statement to do that?

I mean, I would like to put two tables one after the other.

 

Thank you!

6 REPLIES 6
A_Kh
Lapis Lazuli | Level 10

OUTER UNION seems to work in this case. 

SASdevAnneMarie
Barite | Level 11
Thank you ! I have this error four outer join : ERROR 73-322: Expecting an UNION.
A_Kh
Lapis Lazuli | Level 10

Did you use OUTER JOIN or OUTER UNION?

When you use outer union datasets get appended, and all variables are kept (if only UNION, only common variables from input datasets will be kept), and CORR option will align common variables. 

And your error is referring to your syntax, most likely you write OUTER JOIN, instead of OUTER UNION. 

yabwon
Onyx | Level 15
data T1 T2;
input A B C D E F;
if mod(_N_,2) then output T1;
              else output T2;
cards;
1 2 3 4 5 6
2 3 4 5 6 7
3 4 5 6 7 8
4 5 6 7 8 9
5 6 7 8 9 0
;
run;

data t12_ds;
  set  t1 t2;
run;

proc sql;
create table t12_sql as
select * from T1
union ALL
select * from T2
;
quit;
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



SASdevAnneMarie
Barite | Level 11
Thank you,
Is it possible to do the union statement after the left join ?
I have to do the left join with 3 tables and add the last one with union statement.
yabwon
Onyx | Level 15

It's called Maxim#4

 

proc sql;
create table t12_sql as
(
select t1.* 
from T1
left join T3
on t1.A=t3.A
)
union ALL
select * from T2
;
quit;
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 6 replies
  • 871 views
  • 1 like
  • 3 in conversation