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;
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.
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.