BookmarkSubscribeRSS Feed
sastpw
SAS Employee

You can use saspy to upload/download file between client and server. From the SAS Kernel, you can't do anything but submit SAS code, so I don't know how you would do that. FWIW, the sas.submitLST() method from a python Kernel is the equivalent of the SAS Kernel, and you can do so much more w/ python. Just sayin. 

 

Here's an example of using upload (download is similar) to upload a sas data set (can be any file) to the work directory of a viya deployment; that's about the only dir in viya you have write permission to. 

 

>>> sas
Access Method = HTTP
SAS Config name = tth
SAS Config file = /opt/tom/github/saspy/saspy/sascfg_personal.py
WORK Path = /opt/sas/viya/config/var/tmp/compsrv/default/6eca835b-7b16-48df-af86-6dad81576f75/SAS_workF01B000001BE_sas-compute-server-094e063f-11eb-450c-88a6-8261f5b3c3e1-56/
SAS Version = V.04.00M0P10142024
SASPy Version = 5.100.3
Teach me SAS = False
Batch = False
Results = Pandas
SAS Session Encoding = utf-8
Python Encoding value = utf_8
SAS process Pid value = 446
SASsession started = Thu Oct 17 09:23:32 2024


>>> sas.list_tables('work')
[]
>>> sas.dirlist(sas.workpath)
['sasmac3.sas7bcat', 'sasmacr.sas7bcat', 'sastmp-000000004.sas7bitm', 'sas.lck', 'sasgopt.sas7bcat', 'profile.sas7bcat', 'regstry.sas7bitm']
>>> log = sas.upload('a.sas7bdat', sas.workpath)

>>> for item in log: print(item, ':', log[item])
...
Success : True
LOG : 108 filename _sp_updn
108! '/opt/sas/viya/config/var/tmp/compsrv/default/6eca835b-7b16-48df-af86-6dad81576f75/SAS_workF01B000001BE_sas-compute-server-094e
108! 063f-11eb-450c-88a6-8261f5b3c3e1-56//a.sas7bdat' recfm=N permission='';

109 filename _sp_updn;
NOTE: Fileref _SP_UPDN has been deassigned.


>>>

>>> sas.list_tables('work')
[('A', 'DATA')]
>>> sas.dirlist(sas.workpath)
['sasmac3.sas7bcat', 'sasmacr.sas7bcat', 'a.sas7bdat', 'sastmp-000000004.sas7bitm', 'sas.lck', 'sasgopt.sas7bcat', 'profile.sas7bcat', 'regstry.sas7bitm']
>>> sd = sas.sasdata('a')
>>> sd.columnInfo()
Member Num Variable Type Len Pos
0 WORK.A 1.0 x Num 8.0 0.0
>>>

navdeepk
Fluorite | Level 6

So cant we upload file in the Sas drive and access it here? I basically need to upload a csv file and then access it in my code.

sastpw
SAS Employee

I'm afraid I don't know. Were there instructions that came with the free trial you're using? 

navdeepk
Fluorite | Level 6

No, I was able to upload the file and run some code on it using saspy. But even here the uploaded csv is temporary and goes on a random link right. If I wish to run the code again I have to again upload it. Is there any permanent solution for this. Also this was working fine with saspy (python kernel) but with Sas kernel its not the case. From Sas kernel I was not able to upload the file as well.

sastpw
SAS Employee

Yes, that all sounds correct. The SAS_Kernel is just a jupyter extension that calls SASPy under the covers, so all you can do in a SAS notebook is execute SAS code. A Python notebook lets you use SASPy directly and have all the functionality at your disposal. But, in either case, it is just a connection to a single, one time use, SAS Process in a container, in a pod, on the K8S deployment that's Viya. SASPy isn't a Viya application, like say SAS Studio, which is part of Viya itself. I have to believe that SAS Studio would have a way to access the SAS Drive and upload files from your client. 

 

I have to admit, I don't use any of that which is why I don't simply have the answer for you. What would need to happen, is for any SAS session you spin up and connect to in the Viya deployment, there would have to be a libref or fileref that it knows about and can access the 'Drive' you have with whatever data you have in it. I just an not familiar with any of that, but I will do some more investigation to see if I can figure it out. If a SAS session itself can access that, then it should be doable from SASPy. If all of that has to be implemented by a Viya client, and SAS itself had no concept of the SAS Drive component in the Viya deployment (there are hundreds of components in a Viya deployment), then you can't get at any of that from SAS directly via saspy because it's only connected to the SAS process in Viya, not all of the other stuff.

Let me try to figure this out and see what I come up with!

gwootton
SAS Super FREQ
In SAS Code you can use the FILESRVC access method to reference a file in the files service from a filename statement: https://go.documentation.sas.com/doc/en/pgmsascdc/v_052/lestmtsglobal/p0qapul7pyz9hmn0zfoefj0c278a.h...
--
Greg Wootton | Principal Systems Technical Support Engineer
sastpw
SAS Employee

Thanks Greg! @navdeepk that seems like it could be what you need. It seems to allow you to access the folder that you can't with the DISK access method (default for filename). Here's the assignment:

 

79
80 filename x filesrvc folderpath='/Users/sastpw/My Folder';
81 filename x list;
NOTE: Fileref= X
Physical Name= /Users/sastpw/My Folder
82

sastpw
SAS Employee

trying some sample code from that doc on the FILESVC shows it is looking at the 'Drive' where I had uploaded my a.sas7bdat file. I guess I would have to copy it from there to WORK or something to access it via libname, but the file you were looking to get at was a csv, so filename would be what you want, not libname. 

 

So if you upload it with the SAS Drive web page, then you can get at it from Jupyter via the filename FILERVC statement in your SAS code from any SAS session.

 

79
80
81 data _null_;
82 did = dopen('x');
83 mcount = dnum(did);
84 put 'MYFLDR contains ' mcount 'member(s)...';
85 do i=1 to mcount;
86 memname = dread(did, i);
87 put i @5 memname;
88 end;
89 rc = dclose(did);
90 run;
MYFLDR contains 3 member(s)...
1 a.sas7bdat
2 SAS Videos
3 My Snippets
NOTE: DATA statement used (Total process time):
real time 0.77 seconds
cpu time 0.33 seconds

91
92

sastpw
SAS Employee

Ok, well, it doesn’t appear that the SAS Drive is something accessible from a SAS session itself. I connected to a Viya deployment here (not the trial version), and from the SAS Drive web app I could upload a file; uploaded a SAS data set. Then from SAS Studio web app (connected to a SAS session) I could see that data set in ‘My Folders’ which is the Drive thing which is persistent storage (another component in a pod in the viya deployment). I could also right click on the folder or the file and get the path to it; /Users/sastpw/My Folder.

 

However, I couldn’t access that from SAS itself; see the output below. I also tried to add that table to a ‘flow’ in Studio, but it says that’s invalid (I assume cuz SAS can’t access it). I don’t really know what this Drive thing is for, but it only seems accessible from the web components themselves and not directly from SAS.

 

FWIW, in a real viya deployment, you would certainly have some permanent storage configured and mounted to the Compute Servers (that’s the name of the SAS processes – like Workspace Server in SAS 9), such that you would have a filesystem to libname and filename to which would be accessible from each invocation of SAS, just like you would running SAS on a real computer where your local filesystem is available and persistent, even though your WORK library comes and goes with each individual SAS session. I don’t expect that the free trial version of this has any permanent storage location mounted to compute for you to use like this. But in a real deployment, that would be the actual answer to this.

 

Trying to google how to do this I found another community post, asking the same, but with no answers:

https://communities.sas.com/t5/SAS-Programming/Access-SAS-Drive-from-SAS-Studio-Viya-4/td-p/838460

 

And, here’s what happens trying to get at that Drive folder from the SAS session:

 

From a SAS Studio session:

 

79  

80   libname x '/Users/sastpw/My Folder';

ERROR: The path /Users/sastpw/My Folder is not in the list of accessible paths when SAS is in the lockdown state.

ERROR: Error in the LIBNAME statement.

81  

82  

83   *libname _all_ list;

84  

85   libname sasuser list;

NOTE: Libref=   SASUSER

      Scope=    Kernel 

      Engine=   V9

      Access=   READONLY

      Physical Name= /sasuser

      Filename= /sasuser

      Inode Number= 20709938

      Access Permission= rwxrwxrwx

      Owner Name= root

      File Size=              4KB

      File Size (bytes)= 4096

86  

87   data sasuser.a;x=1;run;

ERROR: Write access to member SASUSER.A.DATA is denied.

NOTE: The SAS System stopped processing this step because of errors.

NOTE: DATA statement used (Total process time):

      real time           0.00 seconds

      cpu time            0.00 seconds

     

88  

89   filename x '/Users/sastpw/My Folder/a.sas7bdat';

ERROR: The path /Users/sastpw/My Folder/a.sas7bdat is not in the list of accessible paths when SAS is in the lockdown state.

ERROR: Error in the FILENAME statement.

90 

 

Likewise from  saspy:

 

>>> sas.submitLOG("filename x '/Users/sastpw/My Folder';")

34   filename x '/Users/sastpw/My Folder';

ERROR: The path /Users/sastpw/My Folder is not in the list of accessible paths when SAS is in the lockdown state.

ERROR: Error in the FILENAME statement.

 

 

>>> sas.saslib('x', path='/Users/sastpw/My Folder')

35   libname x    '/Users/sastpw/My Folder'  ;

ERROR: The path /Users/sastpw/My Folder is not in the list of accessible paths when SAS is in the lockdown state.

ERROR: Error in the LIBNAME statement.

 

>>> 

 

 

 

 

 

navdeepk
Fluorite | Level 6

Can we access S3 buckets thorugh sas code ? if local files doesn't work.  How do we setup the S3 credentials . Can I do it in the free trial version? 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Discussion stats
  • 25 replies
  • 4040 views
  • 2 likes
  • 4 in conversation