sassoftware / saspy

A Python interface module to the SAS System. It works with Linux, Windows, and Mainframe SAS as well as with SAS in Viya.
https://sassoftware.github.io/saspy
Other
367 stars 149 forks source link

Connect Base SAS library from SASPY #496

Closed AnandReddy23 closed 1 year ago

AnandReddy23 commented 1 year ago

Hi Team,

We have sas datasets created using SPDE engine on HDFS paths and run below code using saspy in python to connect to underlying tables. import saspy sas = saspy.SASsession() sas.saslib('SS','SPDE','/sas/data','hdfshost=default').

Could you please help me with code to connect to BASE sas library which contains sas views using saspy please ?

I noticed that there is not hdfs path for base sas library as the underlying objects are only sas views. How to connect to these in such scenarios ?

tomweber-sas commented 1 year ago

Hey @AnandReddy23 I'm not sure I understand 100%, but we'll figure it out. So, are you saying that the SPDE library you're assigning above is working? That's good. The BASE engine only accesses SAS data sets (.sas7bdat files), or views (.sas7bvew) which are on accessible filesystems. The base engine has no hdfs kind of options, as it doesn't know anything about hadoop. All the base engine needs for the path is the filesystem path; the directory path where these files live. There are other engines which interact with hadoop. So it depends upon where these BASE engine data sets and views live, and if what you have on hdfs are actually these type of files or not.

An example of the syntax for assigning a base libref would be:

# the base engine is the default, so you don't need to specify it
sas.saslib(libref='x', path='/opt/tom')
# but you can, of course
sas.saslib(libref='x', engine='base', path='/opt/tom)

>>> sas.saslib(libref='x', engine='base', path='/opt/tom')

191
192  libname x base  '/opt/tom'  ;
NOTE: Libref X was successfully assigned as follows:
      Engine:        BASE
      Physical Name: /opt/tom
193
>>> sas.list_tables('x')
[('CHRIS', 'DATA'), ('MVTPRA4', 'DATA'), ('PAGE_VIEWS', 'DATA'), ('SASPY12G', 'DATA'), ('SASPY1G', 'DATA'), ('SASPY4G', 'DATA'), ('TOM1', 'DATA')]
>>>
AnandReddy23 commented 1 year ago

Hi Tom, Many thanks for your response. In my case, all i have is SAS views and as views doesn't hold data, does it still need filesystem path? I use SAS EG, and when I expand on properties there is no mention of filesystem path for these views, which are otherwise visible

tomweber-sas commented 1 year ago

What information does the properties show? Is there a libref associated with them? If so, can you submit a libname list to see how it's assigned?

Libname work list;

But use the libref for them, not work, for your case.

If you want,, we can do a teams meeting so I can see what you have.

tomweber-sas commented 1 year ago

Sorry about that. I'm at lunch and on my phone and I tried to zoom in and accidentally hit close.

tomweber-sas commented 1 year ago

@AnandReddy23 did you see what libref was assigned in your EG session? Assuming you're connecting SASPy to the same workspace server, the same assignment should work. It may even be pre-assigned in the workspace server, if you didn't assign it yourself, which I'm guessing you didn't. In that case, it would already be ready to use. But I don't have any info to know if this is the case or not.

Can you provide any more information about this? Or did you get it to work?

Thanks, Tom

tomweber-sas commented 1 year ago

@AnandReddy23 have you looked at what it is you have assigned in SAS from your EG client? EG is just a client, same as SASPy. They both connect to SAS Workspace servers. If you have a library assigned that works in EG, then you can have the same library assigned from SASPy (it's assigned in the SAS session in either case). I have no information with which to help you, as I don't know what you're seeing from EG, nor what it is that's assigned that you're referring to. If you'd like to pursue this, let me know, else I'll close this this one out.

Thanks, Tom

tomweber-sas commented 1 year ago

without any more information about what you're trying to access, I can't provide the code you need to submit. Here's a link to SAS Doc having to do with what you are saying you want to do; it explains what a libref is, how to assign it and use it and what engines there are which are used to get a different data on different platforms. https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/n12m8wnqd3v3f4n13dezde2yjtrz.htm If you still need help, let me know, but there's nothing else I can do without any info, so I'll close this. Feel free to reopen if you want to purse this. Thanks, Tom

AnandReddy23 commented 1 year ago

Sorry Tom, for not responding earlier. As these were views created on BASE engine, I had to create similar views on Hive and access this through pyspark from python environment. SASPY allows if the SAS tables/objects have physical paths assigned in Libref. In this case there were no physical and was created on metadata, we had to go via Hive.

tomweber-sas commented 1 year ago

So, did you get what you're trying to do to work? SASPy makes no requirements/restrictions on how SAS works. Any libname statement that is valid in SAS can be assigned via saspy. I'm still not really clear on what you have or what you're trying to do. If there is a libname assigned in your EG session that works, that same libname can be assigned via saspy; it's SAS that is doing the work, saspy doesn't change how SAS works.