Hello:
I would like to combine three tables with everything inside by ID and Place. I am trying to use Proc SQL full join so that I don't need to sort the table. I wrote the code below. It seems didn't work.
proc sql;
create table final as
select a.*,
b.*,
c.*
from test1 a
full join test2 b on a.ID=b.ID and a.place=b.place
full join test3 c on a.ID=c.ID and a.place=c.place
where date ne .
order by ID place;
quit;
good observation @novinosrin,
@ybz12003 you may need to add the 'a' alias to the date filter:
proc sql;
create table final as
select
a.*,
b.*,
c.*
from
test1 a
full join test2 b on a.ID = b.ID and a.Place = b.Place
full join test3 c on a.ID = c.ID and a.Place = c.Place
where a.date ne .
order by ID place;
quit;
something like this?
proc sql;
create table final as
select a.*,
b.*,
c.*
from
test1 a
full join test2 b on a.ID = b.ID and a.Place = b.Place
full join test3 c on a.ID = c.ID and a.Place = c.Place
where date ne .
order by ID place;
quit;
I got worning message:
WARNING: Variable id already exists on file WORK.FINAL.
WARNING: Variable place already exists on file WORK.FINAL.
Well that's exactly what rock engineer and I were discussing. You just need to list down col names rather than use *
Too many variables names to list them all, I have 900 for each table.
Switch to datastep. If you want code help, plz post a sample of HAVE and WANT
I think @utrocketeng is in the right direction, but just concerned if date variable exists in more than one dataset, then you may have to prefix it with an alias to avoid ambiguity.
good observation @novinosrin,
@ybz12003 you may need to add the 'a' alias to the date filter:
proc sql;
create table final as
select
a.*,
b.*,
c.*
from
test1 a
full join test2 b on a.ID = b.ID and a.Place = b.Place
full join test3 c on a.ID = c.ID and a.Place = c.Place
where a.date ne .
order by ID place;
quit;
Actually, I popped up another question. I not only want to have the overlapped ID in all of the table but the ID is not duplicated. How to do this?
coalesce(a.id, b.id, c.id) as id
and...I think that if you have records in each table that are duplicate for id and place, then you may need to connect b.place to c.place to keep from generating a cartesian product.
Thanks for all of your wonderful help!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.