Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mf_getapploc.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Returns the appLoc from the _program variable
4 @details When working with SASjs apps, web services / tests / jobs are always
5 deployed to a root (app) location in the SAS logical folder tree.
6
7 When building apps for use in other environments, you do not necessarily know
8 where the backend services will be deployed. Therefore a function like this
9 is handy in order to dynamically figure out the appLoc, and enable other
10 services to be connected by a relative reference.
11
12 SASjs apps always have the same immediate substructure (one or more of the
13 following):
14
15 @li /data
16 @li /jobs
17 @li /services
18 @li /tests/jobs
19 @li /tests/services
20 @li /tests/macros
21
22 This function works by testing for the existence of any of the above in the
23 automatic _program variable, and returning the part to the left of it.
24
25 Usage:
26
27 %put %mf_getapploc(&_program)
28
29 %put %mf_getapploc(/some/location/services/admin/myservice);
30 %put %mf_getapploc(/some/location/jobs/extract/somejob/);
31 %put %mf_getapploc(/some/location/tests/jobs/somejob/);
32
33
34 @author Allan Bowe
35**/
36
37%macro mf_getapploc(pgm);
38%if "&pgm"="" %then %do;
39 %if %symexist(_program) %then %let pgm=&_program;
40 %else %do;
41 %put &sysmacroname: No value provided and no _program variable available;
42 %return;
43 %end;
44%end;
45%local root;
46
47/**
48 * First check we are not in the tests/macros folder (which has no subfolders)
49 */
50%if %index(&pgm,/tests/macros/) %then %do;
51 %let root=%substr(&pgm,1,%index(&pgm,/tests/macros)-1);
52 &root
53 %return;
54%end;
55
56/**
57 * Next, move up two levels to avoid matches on subfolder or service name
58 */
59%let root=%substr(&pgm,1,%length(&pgm)-%length(%scan(&pgm,-1,/))-1);
60%let root=%substr(&root,1,%length(&root)-%length(%scan(&root,-1,/))-1);
61
62%if %index(&root,/tests/) %then %do;
63 %let root=%substr(&root,1,%index(&root,/tests/)-1);
64%end;
65%else %if %index(&root,/services) %then %do;
66 %let root=%substr(&root,1,%index(&root,/services)-1);
67%end;
68%else %if %index(&root,/jobs) %then %do;
69 %let root=%substr(&root,1,%index(&root,/jobs)-1);
70%end;
71%else %put &sysmacroname: Could not find an app location from &pgm;
72 &root
73%mend mf_getapploc ;