Hello
from: http://support.sas.com/documentation/cdl/en/sqlproc/62086/HTML/default/viewer.htm#a001361224.htm
There is no keyword in PROC SQL that returns unique rows from the first and second table, but not rows that occur in both. Here is one way you can simulate this operation:
(query1 except query2) union (query2 except query1)
This example shows how to use this operation.
proc sql;
title 'A EXCLUSIVE UNION B';
(select * from sql.a except select * from sql.b)
union
(select * from sql.b except select * from sql.a);
Thank you for your help.
For the first part, if you're joining by id, then its pretty straightforward depending on which table (if any) would be the "master" table. If neither, then you might consider:
proc sql;
create table want as
select
coalesce(t1,id, t2.id) as ID,
coalesce(t1.a,0) + coalesce(t2.a,0) as a
from
dataset1 t1
full outer join dataset2 t2
on t1.id=t2.id;
quit;
you will have some issues if id is not unique in either table.
For the second part (without testing):
proc sql;
create table want as
select t1.* from (
(select * from sql.a except select * from sql.b)
union
(Select * from sql.b except select * from sql.a)
) t1;
quit;
proc sql;
create table three as
select first.id,sum(first.a,second.a) as a
from first inner join second
on first.id=second.id;
quit;
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 25. Read more here about why you should contribute and what is in it for you!
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.