Hi,
Trying to create a left outer join with a table on the server. TableB is on the server and is a huge table, and TableA is the local table:
PROC SQL;
CREATE TABLE NEW AS
SELECT a.*,
b.VAR1, b.VAR2, b.VAR3, b.VAR4, b.VAR5
FROM TableA AS a
LEFT OUTER JOIN TABLEB AS b
ON a.ID = b.ID;
QUIT;
This code is taking very long actually more than 2 hours. Is there an efficient way I should run this code? like creating a temp table from the server and using that to join TableA.
Thank you
How big is Table A?
If it's smaller, you can consider creating macro variable that has the values you want and then you can filter it first and then join once it's been extracted.
proc sql;
create tableB_Sub as
select b.VAR1, b.VAR2, b.VAR3, b.VAR4, b.VAR5
from tableB as b
where ID in ( LIST OF IDS HERE);
quit;
Then join afterwards.
How big is Table A?
If it's smaller, you can consider creating macro variable that has the values you want and then you can filter it first and then join once it's been extracted.
proc sql;
create tableB_Sub as
select b.VAR1, b.VAR2, b.VAR3, b.VAR4, b.VAR5
from tableB as b
where ID in ( LIST OF IDS HERE);
quit;
Then join afterwards.
Have you validated that there are indexes on the columns you are joining on (a.ID and b.ID)? In my experience, indexes are critical for efficient queries.
When joining a table from the server with a local table SAS firsts brings down the entire table from the server and does the work locally. This is inefficient, so first subsetting the table and bringing it down helps to speed it up.
Reeza,
For the reason you described, i have become a proponet within my company to leverage pass through PROC SQL queries. if the table hosted within SAS is reasonably small, i will write it up to the remote server as a temp table then do the join with that db.
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 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.