BookmarkSubscribeRSS Feed
Miriammess
Calcite | Level 5

Hello, 

 

I'm new in using SAS and I have a problem joining 2 tables together: 

 

I have 1 table that contains the following variables: a, b, c, d, e, f

I have another table that contains the following variables: a, b, c, d, e, f, g

 

I would like to join these tables by a, but when I use a FULL JOIN I got 2 rows with a (a1 and a2) where a2 contains a lot of missing values. When a value is missing in a1 the rest of the variables b, c, d, e, f are also missing, but they were available in my previous table. 

I would like to have the series of number put together without losing information. And I would like to have 1 row of a. 

 

In the attachment you can see that number 2441 is only present in a2, but in my previous table b, c, d, e, f where available. So this information is not included when I join the tables. 

 

Can someone help me? 

I already tried to use a different join, but the results became so weird. I also tried to use append table and than performe a query builder but that gave me also a lot of missing values that were available before. 

By the way: I use SAS EG 7.1


SAS vraag.PNG
6 REPLIES 6
Reeza
Super User

Your join is likely fine, but you need to explicitly deal with the remaining variables that have the same name. 

 

If you want to take the value in either look at the COALESCE/COALESCEC functions. 

LinusH
Tourmaline | Level 20

Side note: COALESCEC is a data step function.

COALESCE works on both numerical and character columns/values in SQL.

Data never sleeps
MeganE
Pyrite | Level 9

I use coalescec in proc sql all the time.  ?

Miriammess
Calcite | Level 5

Thank you so much!

I tried an example of coalesce found on the internet. But where do I put this function in my program?

 

PROC SQL;
CREATE TABLE WORK.SELECTIE AS
SELECT t2.a AS a2,
t1.a1,
t2.b,
t2.c,
t2.d,
t2.e,
t2.f,
t1.g
FROM WORK.SELECTIE3 t1
FULL JOIN WORK.SELECTIE2 ON (t1.a = t2.a);
QUIT;

LinusH
Tourmaline | Level 20

On every column in your SELECT clause where you have overlapping columns names, and the column values shouldn't conflict.

Data never sleeps
ankit___gupta
Quartz | Level 8

Hi Miriammess,

 

Why not try SAS MERGE, to the two tables:

 

 

data <resulttable>;
     merge <table1> <table2>; 
     by a;
run;

 

This will result in the exact same thing that you are expecting from FULL JOIN.

 

--Hope it helps.

 

sas-innovate-2024.png

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.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1275 views
  • 0 likes
  • 5 in conversation