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.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.