2

Does anyone has used the file_delete() method of SASpy? I'm trying to delete a file in SAS Server side using this method but I was unable to make it works.

sas.file_delete(filepath='/au/gac/public/data', fileref='myfile', quiet = False)

I got: AttributeError: 'SASsession' object has no attribute 'file_delete'

Marcio Lino
  • 379
  • 2
  • 15

1 Answers1

3

I just tested this. In 3.3.7 this is not available; in 3.6.6 it is available. I'm not sure exactly what version it was added in (most likely 3.5.0, that seemed to be a big update), but most likely you just need to run:

pip install saspy --upgrade

(While SASPY is not open) and it will work.


Separately, now that we have the right version, I think you may be misunderstanding the arguments to file_delete.

filepath should not just be the folder path - it should include the filename. I don't know exactly how AIX handles these things, but the fileref is not to tell SAS what file you want - it's actually just used in filename [fileref] [filepath]; in the actual SAS code. I'm not really sure why you'd even want this, except perhaps to later do something with that fileref.

Make sure your filepath includes the entire directory tree plus the filename of what you want to delete.

Joe
  • 62,789
  • 6
  • 49
  • 67
  • I was using version 3.3.6 – Marcio Lino Apr 22 '21 at 15:45
  • Did work now, but I got The "filepath provided does not exist". I'm pretty sure the path is correct. – Marcio Lino Apr 22 '21 at 16:08
  • Hmm, worked fine for me... `rc = sas.file_delete("h:/temp/test.txt")` Are you confident SAS can see the file? Maybe consider passing the delete as SAS code - to see if it's possible - and if that fails then you know it's not SASPy but it's something with SAS's inability to see it. – Joe Apr 22 '21 at 16:31
  • Here we have a SAS server running in AIX and, Yes, I can delete the file if do sas.saslib(libref="mylib", path="/au/ga/data") and then sas.submit('proc delete data=mylib.file; run;') – Marcio Lino Apr 22 '21 at 19:01
  • Using sas.file_delete() I got that The "filepath provided does not exist" message mentioned above. – Marcio Lino Apr 22 '21 at 19:04
  • Hmm, try looking at the log? `print(rc['LOG'])` if you ran `rc = sas.file_delete...`. That is where the message comes from (there is a return from there) but it will also show what SAS saw when you passed it that. – Joe Apr 22 '21 at 19:05
  • Oh, now I think I see the issue; will edit the answer. – Joe Apr 22 '21 at 19:08
  • I will give a try tomorrow, and let you know. Thanks – Marcio Lino Apr 22 '21 at 20:14
  • 1
    Hi Joe! I tried today using your tip, and it works. So, as you said, the filepath must include the file name, e.g. sas.file_delete(filepath='/au/gac/public/data/myfile.sas7bdat', quiet = True). Thanks for your help. – Marcio Lino Apr 23 '21 at 11:38