mfv_existfolder.sas
Go to the documentation of this file.
1 /**
2  @file
3  @brief Checks whether a folder exists in SAS Drive
4  @details Returns 1 if the folder 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_existfolder(/does/exist);
13  %put %mfv_existfolder(/does/not/exist);
14 
15  @param [in] path The path to the folder on SAS drive
16 
17  <h4> SAS Macros </h4>
18  @li mf_abort.sas
19  @li mf_getuniquefileref.sas
20 
21  <h4> Related Macros </h4>
22  @li mfv_existfile.sas
23 
24  @version 3.5
25  @author [Allan Bowe](https://www.linkedin.com/in/allanbowe/)
26 **/
27 
28 %macro mfv_existfolder(path
29 )/*/STORE SOURCE*/;
30 
31  %mf_abort(
32  iftrue=(&syscc ne 0),
33  msg=Cannot enter mfv_existfolder.sas with syscc=&syscc
34  )
35 
36  %local fref rc;
37  %let fref=%mf_getuniquefileref();
38 
39  %if %sysfunc(filename(fref,,filesrvc,folderPath="&path"))=0 %then %do;
40  1
41  %let rc=%sysfunc(filename(fref));
42  %end;
43  %else %do;
44  0
45  %let syscc=0;
46  %end;
47 
48 %mend mfv_existfolder;