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-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
  • 4 replies
  • 1492 views
  • 0 likes
  • 3 in conversation