Production Ready Macros for SAS Application Developers
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  %mm_assign_lib(SOMEREF);
10 
11  <h4> Dependencies </h4>
12  @li mf_abort.sas
13 
14  @param libref the libref (not name) of the metadata library
15  @param mDebug= set to 1 to show debug messages in the log
16  @param mAbort= set to 1 to call %mf_abort().
17 
18  @returns libname statement
19 
20  @version 9.2
21  @author Allan Bowe
22 
23 **/
24 
25 %macro mm_assignlib(
26  libref
27  ,mDebug=0
28  ,mAbort=0
29 )/*/STORE SOURCE*/;
30 
31 %local mD;
32 %if &mDebug=1 %then %let mD=;
33 %else %let mD=%str(*);
34 %&mD.put Executing mm_assignlib.sas;
35 %&mD.put _local_;
36 
37 %if &mAbort=1 %then %let mAbort=;
38 %else %let mAbort=%str(*);
39 
40 %if %sysfunc(libref(&libref)) %then %do;
41  %local mf_abort msg; %let mf_abort=0;
42  data _null_;
43  length lib_uri LibName $200;
44  call missing(of _all_);
45  nobj=metadata_getnobj("omsobj:SASLibrary?@Libref='&libref'",1,lib_uri);
46  if nobj=1 then do;
47  rc=metadata_getattr(lib_uri,"Name",LibName);
48  put (_all_)(=);
49  call symputx('LIB',libname,'L');
50  end;
51  else if nobj>1 then do;
52  call symputx('mf_abort',1);
53  call symputx('msg',"More than one library with libref=&libref");
54  end;
55  else do;
56  call symputx('mf_abort',1);
57  call symputx('msg',"Library &libref not found in metadata");
58  end;
59  run;
60  %mf_abort(iftrue= (&mf_abort=1)
61  ,mac=mm_assignlib.sas
62  ,msg=&msg
63  )
64  libname &libref meta library="&lib";
65  %if %sysfunc(libref(&libref)) %then %do;
66  %mf_abort(msg=mm_assignlib macro could not assign &libref
67  ,mac=mm_assignlib.sas);
68  %end;
69 %end;
70 %else %do;
71  %&mD.put NOTE: Library &libref is already assigned;
72 %end;
73 %mend;