BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AZIQ1
Quartz | Level 8

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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.

View solution in original post

5 REPLIES 5
Reeza
Super User

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.

AZIQ1
Quartz | Level 8
Thank you this worked.
utrocketeng
Quartz | Level 8

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.

Reeza
Super User

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. 

 

utrocketeng
Quartz | Level 8

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.

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

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
  • 5 replies
  • 909 views
  • 3 likes
  • 3 in conversation