I'm using code inherited from someone else. The tables being used are being connected to using the sybase connection directly in the proc sql statement (see code below ). I've done some performance testing and this is faster than using a libname statement.
However, I have some tables that I'd like to pull in that are in a SAS library but since they aren't in the sybase database, that's not working. Two are basically just used for indicators so I was able to use a macro variable for that. However, one table has over 100K observations and I need to pull in a field from that table.
So my question is basically, is there a way to join a table using the sybase connection with a SAS table in one step? Or do I just need to use two steps?
Thanks!
PROC SQL;
CONNECT TO sybase(server=&server.
database=&databse.
user=&user.
password=&password.);
Create table Table as
Select *
From Connection to Sybase(
Select
.
.
.
%put &sqlxmsg;
Disconnect from Sybase;
quit;
Yes you can.
The code in blue below is SAS code and the code in red is Sybase code.
You can add any SAS code at all. For example:
libname SYB sybase server=&server database=&databse user=&user pwd=&pwd;
proc sql;
connect using SYB;
create table TABLE as
select *
from connection to SYB (
select ...
) a
left join
SASLIB.SASTABLE b
on a.ID=b.ID
;
%put &sqlxmsg;
quit;
@ChrisNZ That's really helpful. This is (probably) a stupid question, but how would I pull in fields from table B?
Add them to your SELECT statement.
select * means all variables from all tables
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.