BookmarkSubscribeRSS Feed
Albr0166
Fluorite | Level 6

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;
4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

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;

Albr0166
Fluorite | Level 6

@ChrisNZ That's really helpful.  This is (probably) a stupid question, but how would I pull in fields from table B?

SASKiwi
PROC Star

Add them to your SELECT statement.

ChrisNZ
Tourmaline | Level 20

select *   means all variables from all tables

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1244 views
  • 3 likes
  • 3 in conversation