import win32com.client username = "user" password = "pswd" iomhost = "hostname" iomport = 8591 factory = win32com.client.Dispatch("SASObjectManager.ObjectFactoryMulti2") serverDef = win32com.client.Dispatch("SASObjectManager.ServerDef") serverDef.MachineDNSName = iomhost serverDef.Port = iomport serverDef.Protocol = 2 serverDef.ClassIdentifier = "440196d4-90f0-11d0-9f41-00a024bb830c" print('Start Connection') SASApp = factory.CreateObjectByServer("SASApp",True,serverDef,username,password) print('Connection successful') program = "options formchar='|----|+|---+=|-/\<>*';" program += "ods listing;proc means data=sashelp.cars mean mode min max; run;" SASApp.LanguageService.Submit(program) _list = SASApp.LanguageService.FlushList(999999) print(_list) log = SASApp.LanguageService.FlushLog(999999) print(log) SASApp.Close()
I have installed required packages and using Python 3.7. I have executed the above code in eclipse and it terminated with the below message.
and terminated without 'Connection Successful' message. When executing the same code line by line in Python IDLE, after the code
SASApp = factory.CreateObjectByServer("SASApp",True,serverDef,username,password)
Python stopped working unexpectedly as shown in the screenshot.
Could anyone please help me to find what will be actual issue.
Thanks in advance..
Not sure what's causing the crash in Python. But, have you considered using SASPy? It's open source and supported well by SAS developers. It doesn't use the win32com connection -- instead, it relies on Java jars that you can lift from your SAS installation.
Saspy is not compatible for Python 3.4 or higher and SAS 9.4 or higher. SAS 9.3 was installed on my system. Still tried to configure saspy for SAS 9.3 and got the below error
Is there any possibility to connect to SAS 9.3 using saspy, please help me for the same.
Any other suggestions to connect my sas server to python 3.7 are welcome.
Ah, you're correct -- SASPy is built for 9.4 and higher. It relies on some 9.4 features (like HTML5 support) so it's unlikely that support for earlier versions would be added.
So...back to your Python crash. I'm not sure what's going on, but I would try to add more object-inspection code (and maybe run in a debugger) leading up to the line that crashes.
Update: The SASPy project has been updated to support IOM via the Windows client (using win32). You can use the project as-is or examine the source to adapt for your own Python-to-SAS connection. This allows you to bypass the Java dependency and it might even allow a connection to a SAS 9.3, although that hasn't been tested. I know that SASPy relies on the HTML5 destination in ODS, which is in SAS 9.4.
pywin32 is a very finicky library. Make sure you have the correct version installed for your version of Python and bittedness.
Use this link to get a good version of pywin32 and see if that resolves your issue.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.