tags:

views:

325

answers:

2

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?

A: 

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.

Martin Bøgelund
A: 

I know zilch about SAS, but the function used to connect to a database on the fly in ODBC is SQLDriverConnect. You don't need (or want) to add a DSN, you just need the drivers installed.

anon