BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ronein
Onyx | Level 15

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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

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;

View solution in original post

2 REPLIES 2
andreas_lds
Jade | Level 19

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;
Ronein
Onyx | Level 15

Thank you

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1515 views
  • 1 like
  • 2 in conversation