BookmarkSubscribeRSS Feed
Ujjawal
Quartz | Level 8

I am using EG5.1. Is there a way we can delete excel file that is already saved on a server?

I am using the code below. I want to delete XLS if it exists already in this path - /fts/sas/bhandari/.

ODS HTML FILE = "/fts/sas/bhandari/results.xls";

PROC PRINT DATA = A;

RUN;

PROC PRINT DATA = A;

RUN;

ODS HTML CLOSE;

Is there a better way to output the result in a single data set or excel file? I have 2-3 tables. I want to stack the results. Each output is structured differently. I cannot use SET statement to combine them.

Thanks in anticipation!

5 REPLIES 5
Tom
Super User Tom
Super User

SAS now has an FDELETE() function that can delete a file.

Why not just PROC EXPORT to create an XLS file? 

Or ODS TAGSETS.EXCELXP it you really want to make a single sheet that two independent tables.

Kurt_Bremser
Super User

You are creating HTML content and write it to a file with a .xls extension. VERY bad style.

Use .html as the extension!

If you want to create something that will show well in Excel, including formatting and using multiple sheets, or multiple reports within one sheet, look at ODS TAGSETS.EXCELXP. Use .xml as the extension for the output file, as TAGSETS.EXCELXP creates XML code, and Excel may complain when opening a file where the content does not correspond to the filename extension.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, do you have permissions to read/write to that area?  Is there a reason why you need to delete the file?  As mentioned by JurtBremser, tagsets.excelxp will produce nicer looking XML files which Excel can read, however, what is the reason behind using Excel?  Other than a specific request for something in Excel, and then more fool the person asking, I would never choose that as an output format for any purpose, its not a good transfer format, and review wise its to open to abuse.

BrunoMueller
SAS Super FREQ

Hi

Find below a code example where the FDELETE function is used in a macro

%macro fdel(file);
 
%local fref;
  %let fref = __fdel;

 
%if %sysfunc( fileexist(&file) ) = 0 %then %do;
   
%put WARNING: &sysmacroname &file does not exist;
    %return;
 
%end;
 
%let rc= %sysfunc( filename(fref,&file) );
  %let rc= %sysfunc( fdelete(&fref) );
  %let rc= %sysfunc( filename(fref, ) );
%mend;

%let delfile = /tmp/deleteTest.txt;

data _null_;
 
file "&delfile";
 
put "test";
run;

%
fdel(&delfile)


Bruno

SuryaKiran
Meteorite | Level 14

Hi,

 

Thank you. This is helpful, in my environment I was not allowed to use xcommands and found this as my solution for a way how to delete files without using Xcommands.

Thanks,
Suryakiran

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 3275 views
  • 1 like
  • 6 in conversation