Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mfv_getpathuri.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Returns the uri of a file or folder
4 @details The automatic variable `_FILESRVC_[fref]_URI` is used after assigning
5 a fileref using the filesrvc engine. If the path does not exist the macro
6 prints a note, returns nothing, and resets syscc to zero.
7
8 A non zero syscc on entry means an earlier step has already failed. The macro
9 logs a %str(ERR)OR: line and returns an empty uri without touching syscc, so a
10 caller that tests the uri for blankness sees no path, and the failure stays
11 visible in syscc.
12
13 Usage:
14
15 %put %mfv_getpathuri(/Public/folder/file.txt);
16 %put %mfv_getpathuri(/Public/folder);
17
18 @param [in] filepath The full path to the file on SAS drive
19 (eg /Public/myfile.txt)
20
21 <h4> SAS Macros </h4>
22 @li mf_getuniquefileref.sas
23
24 <h4> Related Macros </h4>
25 @li mfv_existfile.sas
26 @li mfv_existfolder.sas
27
28 @version 3.5
29 @author [Allan Bowe](https://www.linkedin.com/in/allanbowe/)
30**/
31
32%macro mfv_getpathuri(filepath
33)/*/STORE SOURCE*/;
34
35 %local fref rc path name var /* var is used to avoid delete timing issue */;
36
37 %if &syscc ne 0 %then %do;
38 %put %str(ERR)OR: mfv_getpathuri.sas cannot execute with syscc=&syscc;
39 %return;
40 %end;
41
42 %let fref=%mf_getuniquefileref();
43 %let name=%scan(&filepath,-1,/);
44 %let path=%substr(&filepath,1,%length(&filepath)-%length(&name)-1);
45
46 %if %sysfunc(filename(fref,,filesrvc,folderPath="&path" filename="&name"))=0
47 %then %do;
48 %let var=_FILESRVC_&fref._URI;
49 %str(&&&var)
50 %let rc=%sysfunc(filename(fref));
51 %symdel &var;
52 %end;
53 %else %do;
54 %put &sysmacroname: did not find &filepath;
55 %let syscc=0;
56 %end;
57
58%mend mfv_getpathuri;