How can I create an ODBC connection to SAS?

Posted by Chris B. on Stack Overflow See other posts from Stack Overflow or by Chris B.
Published on 2010-03-01T17:04:29Z Indexed on 2010/06/08 15:02 UTC
Read the original article Hit count: 205

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about odbc

Related posts about sas