Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mfv_existfile.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Checks whether a file exists in SAS Drive
4 @details Returns 1 if the file exists, and 0 if it doesn't. Works by
5 attempting to assign a fileref with the filesrvc engine. If not found, the
6 syscc is automatically set to a non zero value - so in this case it is reset.
7 To avoid hiding issues, there is therefore a test at the start to ensure the
8 syscc is zero.
9
10 Usage:
11
12 %put %mfv_existfile(/does/exist.txt);
13 %put %mfv_existfile(/does/not/exist.txt);
14
15 @param [in] filepath The full path to the file on SAS drive
16 (eg /Public/myfile.txt)
17
18 <h4> SAS Macros </h4>
19 @li mf_abort.sas
20 @li mf_getuniquefileref.sas
21
22 <h4> Related Macros </h4>
23 @li mfv_existfolder.sas
24
25 @version 3.5
26 @author [Allan Bowe](https://www.linkedin.com/in/allanbowe/)
27**/
28
29%macro mfv_existfile(filepath
30)/*/STORE SOURCE*/;
31
32 %mf_abort(
33 iftrue=(&syscc ne 0),
34 msg=Cannot enter mfv_existfile.sas with syscc=&syscc
35 )
36
37 %local fref rc path name;
38 %let fref=%mf_getuniquefileref();
39 %let name=%scan(&filepath,-1,/);
40 %let path=%substr(&filepath,1,%length(&filepath)-%length(&name)-1);
41
42 %if %sysfunc(filename(fref,,filesrvc,folderPath="&path" filename="&name"))=0
43 %then %do;
44 %sysfunc(fexist(&fref))
45 %let rc=%sysfunc(filename(fref));
46 %end;
47 %else %do;
48 0
49 %let syscc=0;
50 %end;
51
52%mend mfv_existfile;