Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mm_assignlib.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Assigns a meta engine library using LIBREF
4 @details Queries metadata to get the library NAME which can then be used in
5 a libname statement with the meta engine.
6
7 usage:
8
9 %macro mp_abort(iftrue,mac,msg);%put &=msg;%mend;
10
11 %mm_assignlib(SOMEREF)
12
13 <h4> SAS Macros </h4>
14 @li mp_abort.sas
15
16 @param [in] libref The libref (not name) of the metadata library
17 @param [in] mAbort= (HARD) If not assigned, HARD will call %mp_abort(), SOFT
18 will silently return
19
20 @returns libname statement
21
22 @version 9.2
23 @author Allan Bowe
24
25 @sasjslint {"noBannedStrings": false}
26**/
27
28%macro mm_assignlib(
29 libref
30 ,mAbort=HARD
31)/*/STORE SOURCE*/;
32%local mp_abort msg;
33%let mp_abort=0;
34%if %sysfunc(libref(&libref)) %then %do;
35 data _null_;
36 length liburi LibName msg $200;
37 call missing(of _all_);
38 nobj=metadata_getnobj("omsobj:SASLibrary?@Libref='&libref'",1,liburi);
39 if nobj=1 then do;
40 rc=metadata_getattr(liburi,"Name",LibName);
41 /* now try and assign it */
42 if libname("&libref",,'meta',cats('liburi="',liburi,'";')) ne 0 then do;
43 putlog "&libref could not be assigned";
44 putlog liburi=;
45 /**
46 * Fetch the system message for display in the abort modal. This is
47 * not always helpful though. One example, previously received:
48 * NOTE: Libref XX refers to the same library metadata as libref XX.
49 */
50 msg=sysmsg();
51 if msg=:'ERROR: Libref SAVE is not assigned.' then do;
52 msg=catx(" ",
53 "Could not assign %upcase(&libref).",
54 "Please check metadata permissions! Libname:",libname,
55 "Liburi:",liburi
56 );
57 end;
58 else if msg="ERROR: User does not have appropriate authorization "!!
59 "level for library SAVE."
60 then do;
61 msg=catx(" ",
62 "ERROR: User does not have appropriate authorization level",
63 "for library %upcase(&libref), libname:",libname,
64 "Liburi:",liburi
65 );
66 end;
67 call symputx('msg',msg,'l');
68 if "&mabort"='HARD' then call symputx('mp_abort',1,'l');
69 end;
70 else do;
71 put (_all_)(=);
72 call symputx('libname',libname,'L');
73 call symputx('liburi',liburi,'L');
74 end;
75 end;
76 else if nobj>1 then do;
77 if "&mabort"='HARD' then call symputx('mp_abort',1);
78 call symputx('msg',"More than one library with libref=&libref");
79 end;
80 else do;
81 if "&mabort"='HARD' then call symputx('mp_abort',1);
82 call symputx('msg',"Library &libref not found in metadata");
83 end;
84 run;
85
86 %put NOTE: &msg;
87
88%end;
89%else %do;
90 %put NOTE: Library &libref is already assigned;
91%end;
92
93%mp_abort(iftrue= (&mp_abort=1)
94 ,mac=mm_assignlib.sas
95 ,msg=%superq(msg)
96)
97
98%mend mm_assignlib;