BookmarkSubscribeRSS Feed
deleted_user
Not applicable
hi guys ,
I have question about using proc sql with outer union :
This is my code :

data a;
input x y $ ;
cards;
1 one
2 two
2 two
3 three
;
data b;
input x z $ ;
cards;
1 one
2 two
4 four


proc sql;
create table both1 as
select * from a outer union
select * from b;
quit;

According to the link :
http://support.sas.com/documentation/cdl/en/sqlproc/62086/HTML/default/a001361224.htm

column x would appear twice in dataset both1 , however when I run the code it only appears once. So there are 3 columns only instead of 4 columns. Message was edited by: jack050
4 REPLIES 4
Cynthia_sas
SAS Super FREQ
Hi:
There is a difference between outer union and outer union corr. If I run the code on the documentation page, I get the same results as those shown in the doc.

cynthia

[pre]
data a;
infile datalines;
input x y $;
return;
datalines;
1 one
2 two
2 two
3 three
;
run;

data b;
infile datalines;
input x z $;
return;
datalines;
1 one
2 two
4 four
;
run;

ods listing;
options nocenter;
proc sql;
title '1) A OUTER UNION B';
select * from work.a
outer union
select * from work.b;
quit;

proc sql;
title '2) A OUTER UNION CORR B';
select * from work.a
outer union corresponding
select * from work.b;
quit;
[/pre]

Output (note that I DO get two X columns for OUTER UNION method -- versus only one X column for OUTER UNION CORR):
[pre]
1) A OUTER UNION B

x y x z
--------------------------------------
1 one .
2 two .
2 two .
3 three .
. 1 one
. 2 two
. 4 four



2) A OUTER UNION CORR B

x y z
----------------------------
1 one
2 two
2 two
3 three
1 one
2 two
4 four
[/pre]
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
SAS is not going to create a new variable for you. Each SAS table/member can have only one occurence of a named column/variable.

Scott Barry
SBBWorks, Inc.


http://support.sas.com/documentation/cdl/en/sqlproc/62086/HTML/default/a001361224.htm#a001361227
Cynthia_sas
SAS Super FREQ
Scott is right, I deliberately didn't mention what would happen if you used CREATE TABLE syntax with your PROC SQL query. A TABLE created from your query would net slightly different results than just the printed display from running a query. Depending on what you want to do, you might really want a join instead of a union.

cynthia
deleted_user
Not applicable
thanks for pointing that out guys , I totally overlooked that the data set and query results are different

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1822 views
  • 0 likes
  • 3 in conversation