New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there any way to browse the sas server directories for browsing files and folders in saspy (for user interface)? How to get SAS server directory tree in SASpy? #182
Comments
Well, no, I don't have any methods for browsing the file system of the SAS server that saspy is connected to. To be access method agnostic, it would need to be SAS code to be submitted to access the file system. SAS itself doesn't have a terribly east interface to use to do this. Looking at functions for this, there are data step functions, though they appear very tedious to try to use to implement a file system browser api. https://go.documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.2&docsetId=lefunctionsref&docsetTarget=p1bhwd0nlni4own1ia79mj0n29hv.htm&locale=en Here's just an example to get basic current directory info.
An alternative would be to use the X command, though that is frequently disabled on remote production servers. If you can use it, you can simply issue OS terminal commands to browse the FS and parse the info out of the log.
I doubt either of these are what you were hoping for. But, what are your thoughts? How were you looking to use this? Any interest in implementing this functionality? For just a simple directory listing method, I suppose I could explore using the datastep and those functions to produce that. Seems clunky, but should be able to work. Thanks, |
That's my last option using data step to get the directory tree structure. Just wanted to check if something is available for user interface. I would need to do some crazy stuffs to have end user to browser the datasets in python web page.. |
Yes, I'm currently trying to use some of these functions to just get a directory list. Our examples in our doc don't help that much, unfortunately. But, I'll cobble something together and provide a prototype of this, so you can see if you think it would be helpful, or at least a start of what you're looking for. |
Sure. That helps. |
ok, here's something to poke at. I appended the os separator to the directories to distinguish from files. I could return a dictionary with dir or file instead. Depends upon what you want and how'd you use this,
Here's a little helper for separating dirs and files:
So, what are you thinking with this. What functionality would you like more than just this? What format would you like, list, dict, ...? What all methods to do some of this? Is this even in the right direction? Tom |
Here's a run from Windows. This won't work right on MVS though. I'd have to do something different for that. I assume you're not wanting this for MVS, right? :)
|
Exactly.. This is what I expecting from the SAS directory(If pass some path to saspy. Yes, I do not want it for MVS. List should be fine i guess. Our next step would be making this list of files/folders to tree structure in python. |
Is building some kind of tree structure something you would do with this method? Or are you looking for saspy to provide some further functionality to do that? Need other helper methods? What are you looking for this to be (data structure) or look like (just a printed hierarchy)? Is it to be a traversable object or just something to display? Like 'tree' in DOS: ├───comtypes-1.1.2-py3.6.egg-info C:\ProgramData\Anaconda3\Lib\site-packages\saspy>tree Thanks, |
if saspy provide a way to choose a file from above tree (just like prompting) it would be easy for users |
Can you show me what that would look like? Pssudo code with example output? I'm not completely sure I understand. If you choose a file, what happens? |
something like this |
So, you're implementing this UI, and would populate it with the list of files returned from calling sas.dirlist()? |
Yes. you are right. |
After the choosing the file, I will run thru sas.submit and render the output in python web page. |
Ok, so what else do you need? You start with some path and call sas.dirpath(). They click on a file or directory. If dir, then you run that through dirpath() and display those results. So you can navigate up and down already. |
if it is dataset, it should return dataframe or if it is .sas, execute the code and return the log. if it is excel, open the file using local machine's excel.exe |
@mailbagrahul I've pushed this dirlist() to master so you can try it out and see how it works for you. Thanks, |
I think you posted on the wrong issue. Did you get the code from master, or just do |
you can install from master this way: |
If you're configuration's in your sascfg_personal.py, like it ought to be, you can just do the following: pip uninstall saspy and you should be good to go. pip uninstall saspy Tom |
Or you can just copy sasbase.py from master into the install you have. Any of the above. |
Oops. I updated the comments in the wrong window. |
Awesome. I got the list of files from the path given. Thanks a ton.!!! |
Is there a way, i get the pid ? so that I can open the subprocess until the user logout. |
Which pid are you looking for? The SAS server pid? |
I mean the sas session id. I can open the session when the user signs in and disconnect after signs out. |
The SAS pid is available off the SASsession object in the code you pulled from master.
Is that the id you're looking for? The OS process id of the SAS process itself? |
I believe that may be the session id. Let me try to open two session at once and do some stuffs. |
So, What I did was. I opened SASsession and killed it explicitly and then i tried above statements. I used sas.disconnect() to terminate the session, is that not the right way to end the session? From your comment I understand that sas._endsas would terminate the session and clear out all the variables to None, Am I correct? |
disconnect() is something different. |
ahh. Just read the disconnect topic - https://sassoftware.github.io/saspy/advanced-topics.html#disconnecting-from-an-iom-session-and-reconnecting-back-to-it |
Well the SASsession will stay open until you close it,(_endsas()) or untill the SASsession object is deleted, or the python process terminates. |
Ok. I'm running thru local host by flask to connect saspy. I guess I'm not explicitly deleting the object or terminating the process. Let me find out whats happening at the background |
Should I use set_batch() for scripts that runs thru cmd? |
set_batch(True) will change the behavior of methods which return results. Instead of displaying the results (tables, grapsh, plots ....) they will return a dictionary, like the submit() method, with the result and the log. That way you can programatically interact with the result. |
Hi Tom - I have 2 questions for you. 1.Is there a way to retrieve all the datasets from the specified library from sas to dataframe? One of my process runs a sas code that delivers more than 1 dataset that I would like to visualize in frontend using DASH package. I can do it for individual dataset. Its time taking for each request for sas server and fetch the data.
Any thoughts? |
There isn't a method to pull every data set in a library over to a data frame, but that wouldn't be too hard to implement. I also don't have a method to copy a file from the remote server back to the client; I wondered what you were going to do there a while back. I do have another issue (#187) asking for a file transfer method, so I was going to look into a generic file upload/download functionality. But I haven't started on that yet. |
Great thanks. Pulling datasets to dataframes is the main focus for now. I'm making recursive request to server to pull the data. If it is not hard for you to implement, that would be great for anyone using saspy. For file transfer, I want to download the files, render it on html page, make updates on the page itself and save it back to server. |
ok, I've put something together for this. Want to run it by you to get some feedback. I defined a method which, given a libref, returns a dataframe with the member names and memtypes (data or view) as those are what I can access via sd2df(). With that method, you can then iterate over the results and create a dataframe for every one, or apply some logic to choose some and not others, or whatever; it's python :) Here's an example and the results from doing this.
Blindly creating object with names of whatever member names show up probably isn't a good idea.
That would get you the following dataframe objects:
What do you think? |
Awesome. This should resolve my use case. I will implement this and let you know how it goes. Thanks a lot. Do you have any sample proj/code using class&object to interact with sas? |
Cool. I've pushed this to master. Can you grab it from there and try it out? Is that what you were asking about 'sample proj/code using class&object to interact with sas'; where the method? |
@mailbagrahul In working on the other iisue 187, adding file_info() method, whch kinda goes with dirlist(), I implemented it like this file_info(), where it returned a dataframe (similar implementation). But, for that case a dictionary really seemed to make more sense, and I like saspy to work even w/out Pandas.
So, my question is would you like a simple list instead of it being a dataframe? What do you think? |
Ok, I pushed to master the new version, Now you get a list, but if you specify results-;pandas' you get the dataframe:
I did the same w/ the file_info() wich is also now at master, for #187. Tom |
Cool. List should be lot of simpler for processing. Thanks for doing this to us. |
Can we able to find the username using the process id? Not in saspy. Just a general SAS question. I'm getting below error. I want to find out who is holding the dataset. ERROR: A lock is not available for REPORT._RUN_STAT.DATA Any thoughts? |
Well, where's SAS? Windows or Linux? local or remote? Can you look at pids on the system it's running on?
|
I think it is Linux and remote. We are connecting thru citrix. I want see in SAS eg not saspy. |
Can you use the 'x' command in that scenario?
|
Dang. I do not have access to this window. Any sas eg statements? |
I don't know anything specific about EG. Just SAS code you could submit through it. I don't know of OS type SAS commands to interrogate processes. The X command is the one way to submit actual OS commands to do that kind of thing. |
Hey @mailbagrahul , I have an initial upload implementation. See #187 . It still needs some tweaks, but it's a working prototype. Download will come next. But, as I'm out next week, it may not be till the beginning of the year. |
@mailbagrahul I have an initial implementation of download pushed to the upload-download branch. Still some work to do on it but give it a go if you want and see what you think. I've round tripped the same text, html document, and binary executable with upload/download, even cross platform, and it's working. Again, won't be as fast as scp or ftp, but you probably can't use those to access the remote machine, so working, but a little slower should be better than failing immediately :) Also, as this work is being tracked on #187, can we close this issue, as it was for getting file system info, and that's done? Thanks! |
Yes sure. We can close this ticket. I have some question on file directory list. Let me open a new ticket and follow thru on that. |
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Describe the solution you'd like
A clear and concise description of what you want to happen.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered: