Help using Base SAS procedures

about proc with outer union

Reply
N/A
Posts: 0

about proc with outer union

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
SAS Super FREQ
Posts: 8,743

Re: about proc with outer union

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]
Super Contributor
Super Contributor
Posts: 3,174

Re: about proc with outer union

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
SAS Super FREQ
Posts: 8,743

Re: about proc with outer union

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
N/A
Posts: 0

Re: about proc with outer union

thanks for pointing that out guys , I totally overlooked that the data set and query results are different
Ask a Question
Discussion stats
  • 4 replies
  • 342 views
  • 0 likes
  • 3 in conversation