5
OPTIONS FOR MORE INFORMATION ABOUT DATABASE PROCESSING
SASTRACE=',,,d’ reports what statements SAS has passed to SQL Server for CREATE, DROP, INSERT, DELETE,
UPDATE, or SELECT, so you can confirm that your query is being properly translated. You can learn more about the
other options available with SASTRACE. SASTRACELOC=SASLOG writes that information to the SAS Log. This
can be very helpful if you have an issue with the result set being returned by your query and need to contact SAS
Technical Support. NOSTSUFFIX limits the amount of unnecessary information written.
In the Windows environment, the WORK directory path created for your SAS session looks like _TD9999, where the
temporary directory number “9999” is your Task ID. This is good to know, so I write my WORK path to the SAS Log
every session. For example, if SQL Server times out passing rows to SAS, or your SAS window gets closed, there
can be a zombie task still running in SQL Server with no connection for sending the result set back to SAS, wasting
resources. If this happens, you will want to be able to report the Task ID to IT, so they can kill the zombie task in
SQL Server.
OPTIONS SASTRACE=',,,d’ SASTRACELOC=SASLOG NOSTSUFFIX;
%PUT >>> WORK path is %SYSFUNC(PATHNAME(WORK)) <<<; /* in AUTOEXEC.SAS */
CONCLUSION
Microsoft SQL Server is a relational database with its own dialect of SQL (T-SQL or Transact-SQL.) SAS/ACCESS
®
Interface to ODBC has several methods of retrieving SQL Server data for analyzing in SAS. Use ODBC to access
data in SQL Server databases, schemas, and tables. The simplest way is to use implicit PASSTHRU by assigning a
SAS ODBC LIBNAME to your SQL Server database ODBC Data Source. You can get to SQL Server data by coding
a DATA step or PROC SQL and accessing the LIBNAME with SAS syntax; no T-SQL knowledge needed. This is
likely to be inefficient, but for smaller tables or single use data pulls, it works.
With sufficient user permissions on the server and database, you can CREATE, ALTER, DROP, INSERT, DELETE,
UPDATE, or SELECT SQL Server tables from within SAS using explicit PASSTHRU. If you have JOIN logic
combining many tables or complex WHERE conditions to return a small subset of data, explicit PASSTHRU coding is
a better choice, only returning the result set to SAS. You wrap T-SQL code, which does the heavy lifting inside SQL
Server, into your SAS program with FROM CONNECTION TO and EXECUTE BY ODBC.
Set system OPTIONS to see the SQL code being passed to the database, and be sure to check the SQL Server
return code and message by writing them to the Log..
Create a Windows Data Source ODBC driver and get started with this code in your environment.
KEYWORDS
Nina L. Werner, SAS/ACCESS
®
Interface to ODBC, LIBNAME,
CONNECT TO ODBC, FROM CONNECTION TO ODBC, EXECUTE BY ODBC, DISCONNECT FROM ODBC,
&SQLXRC, &SQLXMSG, MONOTONIC(), SASTRACE, SASTRACELOC=SASLOG, NOSTSUFFIX
REFERENCES
• Bailey, Jeff. An Insider’s Guide to SAS/ACCESS® Interface to ODBC. SGF 2014 Proceedings, Paper
SAS039-2014 http://support.sas.com/resources/papers/proceedings14/SAS039-2014.pdf
• Capobianco, Frank. Explicit SQL Pass-Through: Is It Still Useful? SGF 2011 Proceedings, Paper 105-2011
http://support.sas.com/resources/papers/proceedings11/105-2011.pdf
• Crosbie, Stephen. Does foo Pass-Through? SQL Coding Methods and Examples using SAS® software.
MWSUG 2010 Proceedings, Paper RF-02-2013 http://www.lexjansen.com/mwsug/2013/RF/MWSUG-2013-
RF02.pdf