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.
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;
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.
Ready to level-up your skills? Choose your own adventure.