Loading...
Searching...
No Matches
mpe_refreshlibs.sas
Go to the documentation of this file.
1/**
2 @file mpe_refreshlibs.sas
3 @brief Refreshes the library data catalog
4 @details
5
6 @param [in] etlsource= (0) Defaults to %mf_getuniquename(prefix=refreshlibs), identifies this load
7 in the MPE_DATALOADS audit row. That table is keyed on etlsource together
8 with processed_dttm, libref and dsn, so the uid keeps each load distinct.
9
10 <h4> SAS Macros </h4>
11 @li mf_getuniquename.sas
12 @li dc_getlibs.sas
13 @li mf_getplatform.sas
14 @li bitemporal_dataloader.sas
15
16 @version 9.3
17 @author 4GL Apps Ltd
18 @copyright 4GL Apps Ltd. This code may only be used within Data Controller
19 and may not be re-distributed or re-sold without the express permission of
20 4GL Apps Ltd.
21
22 @sasjslint {"maxLineLength": 100}
23
24**/
25
26%macro mpe_refreshlibs(lib=0
27 ,etlsource=0
28);
29/* a default of 0 rather than a %mf_uid() expression: a default is
30 resolved when the macro is compiled, so it would be one value for the
31 whole session and the audit folder below it would collide on the
32 second call - as it did between the refresh steps of one run */
33%if "&etlsource"="0" %then %let etlsource=%mf_getuniquename(prefix=refreshlibs);
34
35%dc_getlibs(outds=work.mm_getLibs)
36proc sort data=mm_getlibs;
37 by libraryref libraryname;
38run;
39
40data libs0;
41 set mm_getlibs;
42 by libraryref;
43%if &lib ne 0 %then %do;
44 where upcase(libraryref)="%upcase(&lib)";
45%end;
46 if "%mf_getplatform()"="SASMETA" then do;
47 /* note - invalid libraries can result in exception errors. If this happens,
48 configure the dc_viewlib_check variable to NO in Data Controller Settings */
49 rc=libname(libraryref,,'meta',cats('library="',libraryname,'";'));
50 drop rc;
51 if rc ne 0 then do;
52 putlog "NOTE: Library " libraryname " does not exist!!";
53 putlog (_all_) (=);
54 delete;
55 end;
56 end;
57 if not first.libraryref then delete;
58run;
59
60proc sql;
61create table libs1 as
62 select distinct libname
63 ,engine
64 ,path
65 ,level
66 ,sysname
67 ,sysvalue
68 from dictionary.libnames
69 order by libname, level,engine,path;
70
71data libs2;
72 set libs1;
73 length tran $1024;
74 if missing(sysname) then sysname='Missing';
75 select(sysname);
76 when('Access Permission') tran='Permissions';
77 when('Owner Name') tran='Owner';
78 when('Schema/Owner') tran='schema';
79 otherwise tran=sysname;
80 end;
81run;
82
83proc transpose data=libs2 out=libs3;
84by libname level engine path;
85var sysvalue;
86id tran;
87run;
88
89data libs4(rename=(libname=libref));
90 length paths $8192 perms owners schemas $500 permissions owner schema $1024;
91 if _n_=1 then call missing (of _all_);
92 set libs3;
93 by libname;
94 if engine='V9' then engine='BASE';
95 if first.libname then do;
96 retain paths perms owners schemas;
97 paths='('!!quote(trim(path));
98 perms=permissions;
99 owners=owner;
100 schemas=schema;
101 end;
102 else do;
103 paths=trim(paths)!!' '!!quote(trim(path));
104 perms=trim(perms)!!','!!trim(permissions);
105 owners=trim(owners)!!','!!trim(owner);
106 schemas=trim(schemas)!!' '!!trim(schema);
107 end;
108 if last.libname then do;
109 paths=trim(paths)!!')';
110 schemas=cats(schemas);
111 output;
112 end;
113 keep libname engine paths perms owners schemas;
114run;
115
116proc sql;
117create table libs5 as
118 select a.libref
119 ,coalescec(b.engine,a.engine) as engine length=32
120 ,b.libraryname as libname
121 ,a.paths
122 ,a.perms
123 ,a.owners
124 ,a.schemas
125 ,b.libraryid as libid
126 from libs4 a
127 left join libs0 b
128 on upcase(a.libref)=upcase(b.libraryref)
129 where libref not in ('SASWORK','WORK','SASUSER','CASUSER','TEMP','STPSAMP'
130 ,'MAPSGFK');
131
132%bitemporal_dataloader(base_lib=&dc_libref
133 ,base_dsn=MPE_DATACATALOG_LIBS
134 ,append_dsn=libs5
135 ,PK=LIBREF
136 ,etlsource=&etlsource
137 ,loadtype=TXTEMPORAL
138 ,tech_from=TX_FROM
139 ,tech_to=TX_TO
140 ,dclib=&dc_libref
141)
142
143%mend mpe_refreshlibs;