BookmarkSubscribeRSS Feed
msrajkumar95
Calcite | Level 5
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.

Output:

Start Connection

 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.

 

Issue.JPG

 

Could anyone please help me to find what will be actual issue.

 

Thanks in advance..

6 REPLIES 6
ChrisHemedinger
Community Manager

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.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
msrajkumar95
Calcite | Level 5

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

 

Issue1.JPG

 

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.

ChrisHemedinger
Community Manager

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.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
brunobrunelli
Calcite | Level 5

Hi,

 

I have the same problem when I try to connect on SAS 9.3 with Python.

Did you have a solution for this connection? If yes, could you show me how you did to connect python with SAS 9.3, please.

 

Capture.PNG

ChrisHemedinger
Community Manager

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.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
FriedEgg
SAS Employee

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.

 

https://github.com/mhammond/pywin32/releases

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 3461 views
  • 1 like
  • 4 in conversation