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
Diamond | Level 26
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
Diamond | Level 26
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

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 2169 views
  • 0 likes
  • 3 in conversation