* create file ;
filename foo "%sysfunc(pathname(work))\foo.csv";
data _null_;
file foo;
put 'blah blah blah';;
run;
filename foo;
* delete file using macro code ;
%let rc=%sysfunc(filename(________,%sysfunc(pathname(work))\foo.csv)); * works ;
%put &=rc;
%let exists=%sysfunc(fexist(________)); * fails, returns 0 not 1 ;
%put &=exists;
%let rc=%sysfunc(fdelete(________)); * fails, does not delete file ; ;
%put &=rc;
%let exists=%sysfunc(fexist(&________)); * works, returns 1, even though macro variable &foo does not exist ;
%put &=exists;
%let rc=%sysfunc(fdelete(&________)); * works, deletes file ;
%put &=rc;
%let rc=%sysfunc(filename(________));
%put &=rc;
And my SAS log:
27 * create file ;
28 filename foo "%sysfunc(pathname(work))\foo.csv";
29 data _null_;
30 file foo;
31 put 'blah blah blah';;
32 run;
NOTE: The file FOO is:
Filename=G:\SAS\Work\_TD8076_XXXXXXXX_\Prc2\foo.csv,
RECFM=V,LRECL=256,File Size (bytes)=0,
Last Modified=24 July 2019 11:49:24,
Create Time=24 July 2019 11:49:24
NOTE: 1 record was written to the file FOO.
The minimum record length was 14.
The maximum record length was 14.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
33 filename foo;
NOTE: Fileref FOO has been deassigned.
34
35 * delete file using macro code ;
36 %let rc=%sysfunc(filename(________,%sysfunc(pathname(work))\foo.csv)); * works ;
37 %put &=rc;
RC=0
38
39 %let exists=%sysfunc(fexist(________)); * fails, returns 0 not 1 ;
40 %put &=exists;
EXISTS=0
41 %let rc=%sysfunc(fdelete(________)); * fails, does not delete file ; ;
42 %put &=rc;
RC=20004
43
44 %let exists=%sysfunc(fexist(&________)); * works, returns 1, even though macro variable &________ does not exist ;
45 %put &=exists;
EXISTS=1
46 %let rc=%sysfunc(fdelete(&________)); * works, deletes file, even though macro variable &________ does not exist ;
47 %put &=rc;
RC=0
48
49 %let rc=%sysfunc(filename(________));
50 %put &=rc;
RC=0
I admit it's weird, and perhaps I'm missing something, but I don't get it...
... View more