Hello
I used proc export to create an XLSX file.
Then ,I decided that I want to delete the XLSX file .
I am trying to go to the path of the XLSX file and right click and delete but it says that I don't have authorization to do it.
Then I am trying to do it from SAS (by using SAS code)
I don't get any error or warning but I found out that the file was not deleted
/*Step1-Export*/
proc export DATA=sashelp.cars
OUTFILE= "/path/Example1.xlsx"
DBMS=xlsx REPLACE ;
SHEET = "cars";
run;
/*Step2-Delete the XLSX file*/
data _null_;
fname="Example1.xlsx";
rc=filename(fname,"/path/");
if rc = 0 and fexist(fname) then
rc=fdelete(fname);
rc=filename(fname);
run;
You have an error in your data-step. The function filename (not that well documented by sas an example how to use it in a data-step is missing) needs the name of a file-reference as first argument. The file-reference is just a string.
Try:
data _null_;
rc = filename('fname', "path\Example1.xlsx");
put 'filename ' rc=;
if rc = 0 and fexist('fname') then do;
rc=fdelete('fname');
put 'delete ' rc=;
end;
rc=filename('fname');
put rc=;
run;
You have an error in your data-step. The function filename (not that well documented by sas an example how to use it in a data-step is missing) needs the name of a file-reference as first argument. The file-reference is just a string.
Try:
data _null_;
rc = filename('fname', "path\Example1.xlsx");
put 'filename ' rc=;
if rc = 0 and fexist('fname') then do;
rc=fdelete('fname');
put 'delete ' rc=;
end;
rc=filename('fname');
put rc=;
run;
Thank you
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.