SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

SASPy: Cannot Access SAS Libraries That Are Available in DI Studio

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

SASPy: Cannot Access SAS Libraries That Are Available in DI Studio

[ Edited ]

My question relates to the SASPy module for Python and specifically how to connect to all libraries that are available in SAS DI Studio. I have setup a winiomwin connection using the package configuration file. I have the following lines in sascfg.py :

 

SAS_config_names = ['winiomwin']
SAS_config_options = {'lock_down': True}

# build out a local classpath variable to use below for Windows clients
cpW = "C:\\Program Files\\SASHome94\\SASDeploymentManager\\9.4\\products\\deploywiz__94390__prt__xx__sp0__1\\deploywiz\\sas.svc.connection.jar"
cpW += ";C:\\Program Files\\SASHome94\\SASDeploymentManager\\9.4\\products\\deploywiz__94390__prt__xx__sp0__1\\deploywiz\\log4j.jar"
cpW += ";C:\\Program Files\\SASHome94\\SASDeploymentManager\\9.4\\products\\deploywiz__94390__prt__xx__sp0__1\\deploywiz\\sas.security.sspi.jar"
cpW += ";C:\\Program Files\\SASHome94\\SASDeploymentManager\\9.4\\products\\deploywiz__94390__prt__xx__sp0__1\\deploywiz\\sas.core.jar"
cpW += ";C:\\Users\\hsej\\AppData\\Local\\Programs\\Python\\Python36-32\\Lib\\site-packages\\saspy\\java\\saspyiom.jar"

# and, if you've configured iom to use encryption, you need these client side jars
cpW += ";C:\\Program Files\\SASHome94\\SASVersionedJarRepository\\eclipse\\plugins\\sas.rutil_904300.0.0.20150204190000_v940m3\\sas.rutil.jar"
cpW += ";C:\\Program Files\\SASHome94\\SASVersionedJarRepository\\eclipse\\plugins\\sas.rutil.nls_904300.0.0.20150204190000_v940m3\\sas.rutil.nls.jar"
cpW += ";C:\\Program Files\\SASHome94\\SASVersionedJarRepository\\eclipse\\plugins\\sastpj.rutil_6.1.0.0_SAS_20121211183517\\sastpj.rutil.jar"

# Windows client and Windows IOM server
winiomwin = {'java': 'C:\\ProgramData\\Oracle\\java\\javapath\\java.exe',
             'iomhost': 'xx.xxx.xx.xx',
             'iomport': 8591,
             'authkey': 'xxx',
             'encoding': 'windows-1252',
             'classpath': cpW,
             'appserver' : 'xxx'
             }

 

In addition, I have placed the _authinfo file in my home folder and have updated all classpath variables. This connection works technically and I can start my session.

 

I have made a small package that I call odksas (includes my own stuff and output methods for now). I have a method for starting a SAS session in the __init__ module:

 

def create_sas_session_object(batch_mode=True, teach_me_sas=False):
    session = saspy.SASsession(cfgname='winiomwin', results='html')
    session.set_batch(batch_mode)
    session.teach_me_SAS(nosub=teach_me_sas)

    return session

 

I then start a new SAS session via a module in a subdirectory that I call jobs:

 

import odksas
from odksas import output
from odksas.constants import CONSTANTS, SYNTAX

# Start session
sas = odksas.create_sas_session_object()

# Delete all files in output directory
output.delete_all_files_in_directory(CONSTANTS.get('output_directory'))

# Execute code
code = sas.submit(SYNTAX.get('test_1'))
output.get_sas_output(code)
output.get_sas_output(sas.datasets('yyy'))

test = sas.sasdata('data_file_name', 'yyy')
output.get_sas_output(test.describe())
output.get_sas_output(test.head(100))

# SAS model object
cars = sas.sasdata('cars', 'sashelp')
output.get_sas_output(cars.bar('EngineSize'))

stat = sas.sasstat()
my_dict = {'model': 'horsepower = cylinders enginesize', 'by': 'type', 'data': cars.sort('type')}
# Note: ** operator turns the dictionary into keyword parameters
model = stat.reg(**my_dict)
output.get_sas_output(model)

 

This code executes without error (process finished with exit code 0). My output method writes the log and results to a file. Specifically for the stat object, I have made a special output method that will create html output files for each output object available in the SASresults object.

 

Now here is my question:

In DI Studio I can access data that I am not able to access through the SASPy session. How is this possible? I would like to access the same data via the SASPy session.

 

For example, when I "check out" a job with at least one source table and run;

 

libname _ALL_ list;

 

I can access the following libref (log):

 

NOTE: Libref=   xxx
      Scope=    IOM ROOT COMP ENV
      Engine=   BASE
      Physical Name= x:\xxxx\xxxx\xxx\xxx\Data
      Filename= x:\xxxx\xxxx\xxx\xxx\Data

 

However, I cannot access the same libref when I run the same statement (libname _ALL_ list) from the SASPy session. Also when I try to run the libname assignment that works in DI Studio, I get this error:

 

/* Access the data for xxx  */
LIBNAME xxx BASE "x:\xxxx\xxxx\xxx\xxx\Data";
NOTE: Library xxx does not exist.

 

Via the SASPy session, I can access another library that has the same physical name up to level two:

 

NOTE: Libref=   yyy
      Scope=    Object Server
      Engine=   BASE
      Physical Name= x:\xxxx\xxxx\xxx\xxx\data
      Filename= x:\xxxx\xxxx\xxx\xxx\data

 

To be clear: x:\xxxx\xxxx is the same for xxx (displayed in DI Studio) and yyy (displayed in the SASPy session). However, this is likely not relevant to the problem (?)

 

NOTE: I am able to access one of the many data files available in the yyy directory via the SASPy session. I can also access sashelp and sasuser (and other librefs).

 

I am convinced that I am connected to the same workspace server. However, I have checked some macro variables using "%put _All_;". DI Studio is connected to the metadata server (via port 8561), whereas my SASPy configuration file specifies port 8591 (as stated in the documentation).

 

Here are some of the macro variables from the log created by DI Studio/SASPy session:

 

GLOBAL IOMSERVER xxx !!! ONLY IN DI STUDIO
GLOBAL METAPORT 8561 !!! ONLY IN DI STUDIO
GLOBAL METASERVER xxx !!! ONLY IN DI STUDIO
GLOBAL SERVERCLASS WorkspaceServer
GLOBAL _METAUSER xxx
AUTOMATIC SYSHOSTINFOLONG X64_DSRV12 WIN 6.2.9200 Server
AUTOMATIC SYSHOSTNAME xxx
AUTOMATIC SYSPROCESSMODE SAS Workspace Server
AUTOMATIC SYSPROCESSNAME Object Server
AUTOMATIC SYSTCPIPHOSTNAME xxx
AUTOMATIC SYSUSERID xxx
AUTOMATIC SYSVER 9.4

 

I think there is something wrong with my connection, can someone figure it out? I have read the guides and troubleshooting section on the package webpage without finding answers.

 

EDIT
When I use the value stored in the IOMSERVER macro variable as "appserver" in the configuration file, I get the following error in the log file from the SASPy session:

 

AppName='xxx'The application could not log on to the server "xx.xxx.xx.xx:8591". The server configuration is invalid.
SAS process has terminated unexpectedly. RC from wait was: 4294967290
SAS Connection failed. No connection established. Double check you settings in sascfg.py file.  

 


Accepted Solutions
Solution
a month ago
New Contributor
Posts: 2

Re: SASPy: Cannot Access SAS Libraries That Are Available in DI Studio

[ Edited ]

I had to add the full path to the data file directory in the libref assignment, including iomserver and parent directories. Here is an example:

 

/* Assign libref from SASPy session */
LIBNAME mylib BASE "!SAS_REP\xxxx\xxxx\xxx\xxx\Data";

 

NOTE

!SAS_REP is a user-defined environment variable on the Windows client machine, for example: "\\sas-app-x-xx\Data". Remember to add the environment variable to the client machine.

 

However, it is not necessary to use the environment variable. This works as well:

 

/* Assign libref from SASPy session */
LIBNAME mylib BASE "\\sas-app-x-xx\Data\xxxx\xxxx\xxx\xxx\Data";

 

IMPORTANT

Do NOT use the appserver option/key in the configuration file. In the configuration file below, I have removed the appserver key:

 

# Windows client and Windows IOM server
winiomwin = {'java': 'C:\\ProgramData\\Oracle\\java\\javapath\\java.exe',
             'iomhost': 'xx.xxx.xx.xx',
             'iomport': 8591,
             'authkey': 'xxx',
             'encoding': 'windows-1252',
             'classpath': cpW
             }

 

View solution in original post


All Replies
Solution
a month ago
New Contributor
Posts: 2

Re: SASPy: Cannot Access SAS Libraries That Are Available in DI Studio

[ Edited ]

I had to add the full path to the data file directory in the libref assignment, including iomserver and parent directories. Here is an example:

 

/* Assign libref from SASPy session */
LIBNAME mylib BASE "!SAS_REP\xxxx\xxxx\xxx\xxx\Data";

 

NOTE

!SAS_REP is a user-defined environment variable on the Windows client machine, for example: "\\sas-app-x-xx\Data". Remember to add the environment variable to the client machine.

 

However, it is not necessary to use the environment variable. This works as well:

 

/* Assign libref from SASPy session */
LIBNAME mylib BASE "\\sas-app-x-xx\Data\xxxx\xxxx\xxx\xxx\Data";

 

IMPORTANT

Do NOT use the appserver option/key in the configuration file. In the configuration file below, I have removed the appserver key:

 

# Windows client and Windows IOM server
winiomwin = {'java': 'C:\\ProgramData\\Oracle\\java\\javapath\\java.exe',
             'iomhost': 'xx.xxx.xx.xx',
             'iomport': 8591,
             'authkey': 'xxx',
             'encoding': 'windows-1252',
             'classpath': cpW
             }

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 316 views
  • 1 like
  • 1 in conversation