That's not work. The use of fileexist() is wrong. (#Maxim1)
According to the documentation for fileexist() not a fileref but fully a fully qualified path to the file is required (https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n06xm8hwk0t0axn10gj16lfiri43.htm)
To use fileref the solution is FEXIST() function: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0gh473azqo3han1edlhbyt04gxa.htm
Look at this series of examples and it's log to see the issue. In the log the "R:\_TD6720_YABWONL5P_" is the WORK directory location for the running sesion.
Code:
filename myfileE "R:\test_Exists.txt";
filename myfileN "R:\test_NOT_exists.txt";
data _null_; /* create the file */
file myfileE;
put "42";
run;
data _null_;
rc = fexist('myfileE');
rctxt=sysmsg();
put rc= / rctxt=;
run;
data _null_;
rc = fileexist('myfileE');
rctxt=sysmsg();
put rc= / rctxt=;
run;
data _null_;
rc = fexist('myfileN');
rctxt=sysmsg();
put rc= / rctxt=;
run;
data _null_;
rc = fileexist('myfileN');
rctxt=sysmsg();
put rc= / rctxt=;
run;
data _null_;
rc = fileexist("R:\test_Exists.txt");
rctxt=sysmsg();
put rc= / rctxt=;
run;
data _null_;
rc = fileexist("R:\test_NOT_exists.txt");
rctxt=sysmsg();
put rc= / rctxt=;
run;
Log:
1 filename myfileE "R:\test_Exists.txt";
2 filename myfileN "R:\test_NOT_exists.txt";
3
4 data _null_; /* create the file */
5 file myfileE;
6 put "42";
7 run;
NOTE: The file MYFILEE is:
Filename=R:\test_Exists.txt,
RECFM=V,LRECL=32767,File Size (bytes)=0,
Last Modified=20Feb2024:08:08:23,
Create Time=20Feb2024:08:08:23
NOTE: 1 record was written to the file MYFILEE.
The minimum record length was 2.
The maximum record length was 2.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds
8
9
10 data _null_;
11 rc = fexist('myfileE');
12 rctxt=sysmsg();
13 put rc= / rctxt=;
14 run;
rc=1
rctxt=
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
15
16 data _null_;
17 rc = fileexist('myfileE');
18 rctxt=sysmsg();
19 put rc= / rctxt=;
20 run;
rc=0
rctxt=WARNING: Physical file does not exist, R:\_TD6720_YABWONL5P_\myfileE.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
21
22 data _null_;
23 rc = fexist('myfileN');
24 rctxt=sysmsg();
25 put rc= / rctxt=;
26 run;
rc=0
rctxt=WARNING: Physical file does not exist, R:\test_NOT_exists.txt.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
27
28 data _null_;
29 rc = fileexist('myfileN');
30 rctxt=sysmsg();
31 put rc= / rctxt=;
32 run;
rc=0
rctxt=WARNING: Physical file does not exist, R:\_TD6720_YABWONL5P_\myfileN.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
33
34
35
36
37 data _null_;
38 rc = fileexist("R:\test_Exists.txt");
39 rctxt=sysmsg();
40 put rc= / rctxt=;
41 run;
rc=1
rctxt=
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
42
43 data _null_;
44 rc = fileexist("R:\test_NOT_exists.txt");
45 rctxt=sysmsg();
46 put rc= / rctxt=;
47 run;
rc=0
rctxt=WARNING: Physical file does not exist, R:\test_NOT_exists.txt.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
Bart
... View more