sas - Reading sas7bdat files with Python's adodbapi -
i'm trying read sas7bdat file sas (product of sas institute) python.
yes, i'm aware export *.csv files, i'm trying avoid double number of files need create.
there's documentation doing in visual basic. still, want in python. example, in vb write...
dim cn adodb.connection dim rs adodb.recordset obconnection.provider = "sas.localprovider" obconnection.properties("data source") = "c:\mysasdata" obconnection.open rs.open "work.a", cn, adopenstatic, adlockreadonly, adcmdtabledirect to open dataset.
but can't crack nut make work in python.
i can type...
import adodbapi cnstr = 'provider=sas.localprovider;c:\\mysasdata' cn = adodbap.connect(cnstr) and can cursor...
cur = cn.cur() but beyond that, i'm stumped. did find cur.rs, sounds recordset, object type of none.
also, preempt alternative methods...
- i not want create *.csv files in sas.
- the computer python not have sas installed, have providers ole db installed. know fact vb code provided works without sas in read-only mode. can download these drivers here: http://support.sas.com/downloads/browse.htm?cat=64
- i not expert in sas. honestly, find tool cumbersome, confusingly documented, , slow. noticed there other products listed called "iomprovider" , "sas/share". if there's easier way of doing using ado providers, feel free document it. however, i'm looking way of doing entirely within python relatively simple bit of code.
- oh, , i'm aware of python's sas7bdat package, we're using python 3.3.5 , doesn't seem compatible. also, couldn't figure out how use on 2.7 anyways there's not lot of documentation , question on how use tool, which, day, unanswered. python sas7bdat module usage
thanks!
didn't test sas don't have provider installed currently, should go this:
cn = adodbapi.connect(cnstr) # print table names in current db table in cn.get_table_names(): print(table) cn.cursor() c: #run sql statement on cursor sql = 'select * your_table' c.execute(sql) #get results db = c.fetchmany(5) #print them rec in db: print(rec) cn.close() edit: found http://support.sas.com/kb/30/795.html might need use other provider method, have @ iom privoder (https://www.connectionstrings.com/sas-iom-provider/ , http://support.sas.com/documentation/tools/oledb/gs_iom_tasks.htm)
Comments
Post a Comment