Hi All,
Can you please help me getting the below output using sql join
It seems that table b updates table a:
data nn;
update a b;
by id;
run;
What is the logic behind the first row in your want dataset?
Please post your test data as text in a code window (thats the {i} above post area) in future. For an SQL solution:
proc sql; create table WANT as select COALESCE(A.ID,B.ID) as ID, COALESCE(A.NAME,B.NAME) as NAME from A full join B on A.ID=B.ID; quit;
Yep, my code works then.
Yuo would be best off clarify the logic behind why a data item appears in the output, if it is take B value if present else A then swap the coalesce over:
proc sql; create table WANT as select COALESCE(A.ID,B.ID) as ID, COALESCE(B.NAME,A.NAME) as NAME from A full join B on A.ID=B.ID; quit;
A data step variant that leaves the name for ID 1 intact:
data nn;
merge
a
b (rename=(name=_name))
;
by id;
if missing(name) then name = _name;
drop _name;
run;
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.