I'm writing a program that needs to access SAS data. I've downloaded the ODBC drivers for SAS and installed them, but I need to be able to create ODBC connections on the fly, programmatically. The following code (in Python) seems like it should work:
import ctypes
ODBC_ADD_DSN = 1
def add_dsn(name, driver, **kw):
nul, attrib = chr(0), []
kw['DSN'] = name
for attr, val in kw.iteritems():
attrib.append('%s=%s' % (attr, val))
return ctypes.windll.ODBCCP32.SQLConfigDataSource(0, ODBC_ADD_DSN, driver, nul.join(attrib)) == 1
print add_dsn('SAS Test', 'SAS', description = 'Testing SAS')
But it pops up the SAS ODBC configuration dialog, sets the datasource name, and waits for the user to enter the information and dismiss the dialog. How can I avoid that?
SAS/ACCESS Interface to ODBC on UNIX allows SAS customers to present data from a wide variety of external data sources. Many customers using SAS on UNIX have had success using SAS/ACCESS Interface to ODBC with their ODBC client setups.
In order to get ODBC access to SAS data, you need to connect to a running SAS session of some kind; you can't access SAS data table files directly with the SAS ODBC drivers.
See the SAS ODBC drivers guide, section "What Software Do I Need?".
Your question doesn't state that you are trying to access SAS data through a running SAS product. The SAS ODBC drivers guide should tell you how to set up the connection based on the SAS product you will make the connection through.
I know this question is ancient but it probably comes up often enough that I will share the answer I know. The easiest way to achieve what you are trying to do is create what's called a "DSN-Less Connection."
Briefly, you create a connect string that you use when opening a connection, that identifies the driver and includes all the parameters you'd normally fill in in creating a DSN for that driver.
This technique has been around for a very long time-- I was using it in 2001, and it's older than that.
Here is a series of sample DSN-Less connection strings for accessing SAS data via ODBC:
Using Server ID
Provider=sas.ShareProvider;Data Source=shr1;
SAS/SHARE Using Server ID and node (network name) Provider=sas.ShareProvider;Data Source=shr1;Location=lambchop.unx.sas.com;
SAS/SHARE
Specifying user and password
Provider=sas.ShareProvider;Data Source=shr1;Location=lambchop.unx.sas.com;
User ID=myUsername;Password=myPassword;
SAS/SHARE
Server requires a password
Provider=sas.ShareProvider;Data Source=shr1;Location=lambchop.unx.sas.com;
User ID=myUsername;Password=myPassword;
SAS Server Access Password=myServerPassword;
These are from: https://www.connectionstrings.com/sas-share/
A SAS support page discusses this more-- I found it here: http://docslide.us/documents/opening-an-ado-connection-object.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With