Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mm_getlibmetadiffs.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Compares the metadata of a library with the physical tables
4 @details Creates a series of output tables that show the differences between
5 metadata and physical tables.
6 Each output can be created with an optional prefix.
7
8 Credit - Paul Homes
9 https://platformadmin.com/blogs/paul/2012/11/sas-proc-metalib-ods-output
10
11 Usage:
12
13 %* create (and assign) a library for testing purposes ;
14 %mm_createlibrary(
15 libname=My Temp Library,
16 libref=XXTEMPXX,
17 tree=/User Folders/&sysuserid,
18 directory=%sysfunc(pathname(work))
19 )
20
21 %* create some tables;
22 data work.table1 table2 table3;
23 a=1;b='two';c=3;
24 run;
25
26 %* register the tables;
27 proc metalib;
28 omr=(library="My Temp Library");
29 report(type=detail);
30 update_rule (delete);
31 run;
32
33 %* modify the tables;
34 proc sql;
35 drop table table3;
36 alter table table2 drop c;
37 alter table table2 add d num;
38
39 %* run the macro;
40 %mm_getlibmetadiffs(libname=My Temp Library)
41
42 %* delete the library ;
43 %mm_deletelibrary(name=My Temp Library)
44
45 The program will create four output tables, with the following structure (and
46 example data):
47
48 #### &prefix.added
49 |name:$32.|metaID:$17.|SAStabName:$32.|
50 |---|---|---|
51 | | |DATA1|
52
53 #### &prefix.deleted
54 |name:$32.|metaID:$17.|SAStabName:$32.|
55 |---|---|---|
56 |TABLE3|A5XLSNXI.BK0001HO|TABLE3|
57
58 #### &prefix.updated
59 |tabName:$32.|tabMetaID:$17.|SAStabName:$32.|metaName:$32.|metaID:$17.|sasname:$32.|metaType:$16.|change:$64.|
60 |---|---|---|---|---|---|---|---|
61 |TABLE2|A5XLSNXI.BK0001HN|TABLE2|c|A5XLSNXI.BM000MA9|c|Column|Deleted|
62 | | | |d| |d|Column|Added|
63
64 #### &prefix.meta
65 |Label1:$28.|cValue1:$1.|nValue1:D12.3|
66 |---|---|---|
67 |Total tables analyzed|4|4|
68 |Tables to be Updated|1|1|
69 |Tables to be Deleted|1|1|
70 |Tables to be Added|1|1|
71 |Tables matching data source|1|1|
72 |Tables not processed|0|0|
73
74 If you are interested in more functionality like this (checking the health of
75 SAS metadata and your SAS 9 environment) then do contact [Allan Bowe](
76 https://www.linkedin.com/in/allanbowe) for details of our SAS 9 Health Check
77 service.
78
79 Our system scan will perform hundreds of checks to identify common issues,
80 such as dangling metadata, embedded passwords, security issues and more.
81
82 @param [in] libname= the metadata name of the library to be compared
83 @param [out] outlib=(work) The library in which to store the output tables.
84 @param [out] prefix=(metadiff) The prefix for the four tables created.
85
86 @version 9.3
87 @author Allan Bowe
88
89 @sasjslint {"maxLineLength": 112}
90**/
91
92%macro mm_getlibmetadiffs(
93 libname= ,
94 prefix=metadiff,
95 outlib=work
96)/*/STORE SOURCE*/;
97
98 /* create tempds */
99 data;run;
100 %local tempds;
101 %let tempds=&syslast;
102
103 /* save options */
104 proc optsave out=&tempds;
105 run;
106
107 options VALIDVARNAME=ANY VALIDMEMNAME=EXTEND;
108
109 ods output
110 factoid1=&outlib..&prefix.meta
111 updtab=&outlib..&prefix.updated
112 addtab=&outlib..&prefix.added
113 deltab=&outlib..&prefix.deleted
114 ;
115
116 proc metalib;
117 omr=(library="&libname");
118 noexec;
119 report(type=detail);
120 update_rule (delete);
121 run;
122
123 ods output close;
124
125 /* restore options */
126 proc optload data=&tempds;
127 run;
128
129%mend mm_getlibmetadiffs;