Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
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. When the folder is
6 not found the filename function sets syscc to a non zero value, so the macro
7 resets syscc to zero and returns 0.
8
9 A non zero syscc on entry means an earlier step has already failed. The macro
10 logs a %str(ERR)OR: line and returns 0 without touching syscc, so a caller
11 comparing the result against 1 or 0 stays valid, and can tell this case from a
12 genuine miss by checking syscc, which a miss resets to zero.
13
14 Usage:
15
16 %put %mfv_existfolder(/does/exist);
17 %put %mfv_existfolder(/does/not/exist);
18
19 @param [in] path The path to the folder on SAS drive
20
21 <h4> SAS Macros </h4>
22 @li mf_getuniquefileref.sas
23
24 <h4> Related Macros </h4>
25 @li mfv_existfile.sas
26
27 @version 3.5
28 @author [Allan Bowe](https://www.linkedin.com/in/allanbowe/)
29**/
30
31%macro mfv_existfolder(path
32)/*/STORE SOURCE*/;
33
34 %local fref rc var;
35
36 %if &syscc ne 0 %then %do;
37 %put %str(ERR)OR: mfv_existfolder.sas cannot execute with syscc=&syscc;
38 0
39 %return;
40 %end;
41
42 %let fref=%mf_getuniquefileref();
43
44 %if %sysfunc(filename(fref,,filesrvc,folderPath="&path"))=0 %then %do;
45 1
46 %let var=_FILESRVC_&fref._URI;
47 %let rc=%sysfunc(filename(fref));
48 %symdel &var;
49 %end;
50 %else %do;
51 0
52 %let syscc=0;
53 %end;
54
55%mend mfv_existfolder;