How can I create an ODBC connection to SAS?

2024/10/2 16:17:54

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 ctypesODBC_ADD_DSN = 1        def add_dsn(name, driver, **kw):nul, attrib = chr(0), []kw['DSN'] = namefor attr, val in kw.iteritems():attrib.append('%s=%s' % (attr, val))return ctypes.windll.ODBCCP32.SQLConfigDataSource(0, ODBC_ADD_DSN, driver, nul.join(attrib)) == 1print 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?

Answer

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.

https://en.xdnf.cn/q/70834.html

Related Q&A

How to extract links from a page using Beautiful soup

I have a HTML Page with multiple divs like:<div class="post-info-wrap"><h2 class="post-title"><a href="https://www.example.com/blog/111/this-is-1st-post/" t…

Verifying the integrity of PyPI Python packages

Recently there came some news about some Malicious Libraries that were uploaded into Python Package Index (PyPI), see:Malicious libraries on PyPI Malicious modules found into official Python repository…

How to get results from custom loss function in Keras?

I want to implement a custom loss function in Python and It should work like this pseudocode:aux = | Real - Prediction | / Prediction errors = [] if aux <= 0.1:errors.append(0) elif aux > 0.1 &am…

How to tell whether a file is executable on Windows in Python?

Im writing grepath utility that finds executables in %PATH% that match a pattern. I need to define whether given filename in the path is executable (emphasis is on command line scripts).Based on "…

Issue with python/pytz Converting from local timezone to UTC then back

I have a requirement to convert a date from a local time stamp to UTC then back to the local time stamp.Strangely, when converting back to the local from UTC python decides it is PDT instead of the or…

Regex to replace %variables%

Ive been yanking clumps of hair out for 30 minutes doing this one...I have a dictionary, like so:{search: replace,foo: bar}And a string like this:Foo bar %foo% % search %.Id like to replace each var…

Python kivy - how to reduce height of TextInput

I am using kivy to make a very simple gui for an application. Nothing complex, very simple layout.Nevertheless I am having a hard time with TextInputs...They always display with full height and I cant …

Python-Matplotlib boxplot. How to show percentiles 0,10,25,50,75,90 and 100?

I would like to plot an EPSgram (see below) using Python and Matplotlib. The boxplot function only plots quartiles (0, 25, 50, 75, 100). So, how can I add two more boxes?

Python Pandas reads_csv skip first x and last y rows

I think I may be missing something obvious here, but I am new to python and pandas. I am reading a large text file and only want to use rows in range(61,75496). I can skip the first 60 rows withkeyword…

Combine two arrays data using inner join

Ive two data sets in array: arr1 = [[2011-10-10, 1, 1],[2007-08-09, 5, 3],... ]arr2 = [[2011-10-10, 3, 4],[2007-09-05, 1, 1],... ]I want to combine them into one array like this: arr3 = [[2011-10-10, 1…