I need to delete a file in libname if it exists.
It's not right...
%IF %SYSFUNC(TODAY(),DAY.) EQ 1 %THEN %DO;
%IF %SYSFUNC(FILEEXIST(DRM.TRANSF_PARTIAL_&MES.)) %THEN %DO;
%SYSFUNC(FDELETE(DRM.TRANSF_PARTIAL_&MES.));
%END;
%LET FILE=TRANSF_CLOSURE_&MES.;
%END;
If you want to delete a dataset then why not just use PROC DELETE?
%if %sysfunc(today(),day.) eq 1 %then %do;
%let file=TRANSF_CLOSURE_&MES.;
%if %sysfunc(exist(drm.&file)) %then %do;
proc delete data=drm.&file ;
run;
%end;
%end;
Are you attempting to delete a SAS date set or an external non-SAS file? FILEEXIST function checks for the existence of external files, not SAS data sets. You would use EXIST function to determine if a SAS data set or view is present.
FDELETE is intended to delete external files and the reference would be "is a character constant, variable, or expression that specifies the fileref that you assign to the external file or directory. " not a libname.dataset construct. You would have to generate an operating system path/filename instead of the library.dataset reference for Fdelete to work.
Yes, it is external.
Please, how can I put FILEREF in the macro?
Is there a way to delete this file just by pointing to libname?
If you want to delete a dataset then why not just use PROC DELETE?
%if %sysfunc(today(),day.) eq 1 %then %do;
%let file=TRANSF_CLOSURE_&MES.;
%if %sysfunc(exist(drm.&file)) %then %do;
proc delete data=drm.&file ;
run;
%end;
%end;
It worked perfectly when I simulated day 1, thank you.
I was confusing the EXIST functions with FILEEXIST and FDELETE with PROC DELETE. Thanks
%IF %SYSFUNC(TODAY(),DAY.) EQ 1 %THEN %DO;
%IF %SYSFUNC(EXIST(DRM.TRANSF_PARTIAL_&MES.)) %THEN %DO;
PROC DELETE DATA=DRM.TRANSF_PARTIAL_&MES.;
%END;
%LET FILE=TRANSF_CLOSURE_&MES.;
%END;
%ELSE %DO;
%LET FILE=TRANSF_PARTIAL_&MES.;
%END;
@a_ramos wrote:
I need to delete a file in libname if it exists.
It's not right...
%IF %SYSFUNC(TODAY(),DAY.) EQ 1 %THEN %DO;
%IF %SYSFUNC(FILEEXIST(DRM.TRANSF_PARTIAL_&MES.)) %THEN %DO;%SYSFUNC(FDELETE(DRM.TRANSF_PARTIAL_&MES.));
%END;
%LET FILE=TRANSF_CLOSURE_&MES.;
%END;
How is it not right? Are you getting an error? Is it not working? I'm assuming this is wrapped in a MACRO?
Your condition will never be true until the first day of the month so you'll need to change that to test it for sure.
I was confusing the EXIST functions with FILEEXIST and FDELETE with PROC DELETE.
Tom helped me.
Thanks
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.