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

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 4 replies
  • 850 views
  • 3 likes
  • 3 in conversation