BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10
What is difference between
Libname statement and sql pass thru query
3 REPLIES 3
Ksharp
Super User
Libname statement need translate sas sql into local sql,
while pass thru don't , just pass local sql into DB and run sql at DB side ,so it is faster then libname .
SASKiwi
PROC Star

A LIBNAME statement connecting to an external database versus an SQL Passthru doing the same - both have advantages and disadvantages:

 

LIBNAMEs are easier and can be automated for all SAS sessions via SAS metadata or SAS AUTOEXECs but can't handle table names greater than 32 characters long. They can be directly used in DATA steps and many SAS procedures.

 

SQL Passthru is more powerful, more customisable, and is the only way to access table names greater than 32 characters long, but you need to know the SQL syntax of the database you are querying and can only be used in PROC SQL.

 

 

ChrisNZ
Tourmaline | Level 20

This is a badly worded question.

Libnames enable a connection. SQL (passthru or not) can use the connection to access data.

So they are not mutually exclusive. They don't do the same thing.

This means that they be used together:

libname ORADATA oracle user= ....;
proc sql;
  connect using ORADATA;
  select * from (        /* Use SAS SQL before the (         */
     select * from ...   /* Use Oracle SQL between ( and  )  */
  ) ;                    /* Use SAS SQL after the (          */
quit;

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