Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
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 libref the libref (not name) of the metadata library
17 @param mAbort= If not assigned, HARD will call %mp_abort(), SOFT will
18 silently return
19
20 @returns libname statement
21
22 @version 9.2
23 @author Allan Bowe
24
25**/
26
27%macro mm_assignlib(
28 libref
29 ,mAbort=HARD
30)/*/STORE SOURCE*/;
31
32%if %sysfunc(libref(&libref)) %then %do;
33 %local mp_abort msg; %let mp_abort=0;
34 data _null_;
35 length liburi LibName $200;
36 call missing(of _all_);
37 nobj=metadata_getnobj("omsobj:SASLibrary?@Libref='&libref'",1,liburi);
38 if nobj=1 then do;
39 rc=metadata_getattr(liburi,"Name",LibName);
40 /* now try and assign it */
41 if libname("&libref",,'meta',cats('liburi="',liburi,'";')) ne 0 then do;
42 putlog "&libref could not be assigned";
43 call symputx('msg',sysmsg(),'l');
44 if "&mabort"='HARD' then call symputx('mp_abort',1,'l');
45 end;
46 else do;
47 put (_all_)(=);
48 call symputx('libname',libname,'L');
49 call symputx('liburi',liburi,'L');
50 end;
51 end;
52 else if nobj>1 then do;
53 if "&mabort"='HARD' then call symputx('mp_abort',1);
54 call symputx('msg',"More than one library with libref=&libref");
55 end;
56 else do;
57 if "&mabort"='HARD' then call symputx('mp_abort',1);
58 call symputx('msg',"Library &libref not found in metadata");
59 end;
60 run;
61
62 %if &mp_abort=1 %then %do;
63 %mp_abort(iftrue= (&mp_abort=1)
64 ,mac=&sysmacroname
65 ,msg=&msg
66 )
67 %return;
68 %end;
69 %else %if %length(&msg)>2 %then %do;
70 %put NOTE: &msg;
71 %return;
72 %end;
73
74%end;
75%else %do;
76 %put NOTE: Library &libref is already assigned;
77%end;
78%mend mm_assignlib;