From 8246b5a42ce37897d7fbb432771d4af18da416cf Mon Sep 17 00:00:00 2001 From: munja Date: Sat, 3 Sep 2022 16:50:11 +0100 Subject: [PATCH] feat: new mp_dictionary() table --- all.sas | 66 ++++++++++++++++++++++++++++--- base/mp_createconstraints.sas | 15 ++++--- base/mp_dictionary.sas | 50 +++++++++++++++++++++++ sasjs/sasjsconfig.json | 2 +- tests/base/mp_dictionary.test.sas | 26 ++++++++++++ 5 files changed, 146 insertions(+), 13 deletions(-) create mode 100644 base/mp_dictionary.sas create mode 100644 tests/base/mp_dictionary.test.sas diff --git a/all.sas b/all.sas index 59597c7..5707f22 100644 --- a/all.sas +++ b/all.sas @@ -4112,11 +4112,14 @@ proc sql; %mp_deleteconstraints(inds=work.constraints,outds=dropped,execute=YES) %mp_createconstraints(inds=work.constraints,outds=created,execute=YES) - @param inds= The input table containing the constraint info - @param outds= a table containing the create statements (create_statement column) - @param execute= `YES|NO` - default is NO. To actually create, use YES. + @param inds= (work.mp_getconstraints) The input table containing the + constraint info + @param outds= (work.mp_createconstraints) A table containing the create + statements (create_statement column) + @param execute= (NO) To actually create, use YES. -

SAS Macros

+

Related Files

+ @li mp_getconstraints.sas @version 9.2 @author Allan Bowe @@ -4124,7 +4127,7 @@ proc sql; **/ %macro mp_createconstraints(inds=mp_getconstraints - ,outds=mp_createconstraints + ,outds=work.mp_createconstraints ,execute=NO )/*/STORE SOURCE*/; @@ -4158,7 +4161,8 @@ data &outds; output; run; -%mend mp_createconstraints;/** +%mend mp_createconstraints; +/** @file mp_createwebservice.sas @brief Create a web service in SAS 9, Viya or SASjs Server @details This is actually a wrapper for mx_createwebservice.sas, remaining @@ -4450,6 +4454,56 @@ run; %end; %else %put &sysmacroname: &folder: is not a valid / accessible folder. ; %mend mp_deletefolder;/** + @file mp_dictionary.sas + @brief Creates a portal (libref) into the SQL Dictionary Views + @details Provide a libref and the macro will create a series of views against + each view in the special PROC SQL dictionary libref. + + This is useful if you would like to visualise (navigate) the views in a SAS + client such as Base SAS, Enterprise Guide, or Studio (or [Data Controller]( + https://datacontroller.io)). + + It works by extracting the dictionary.dictionaries view into + YOURLIB.dictionaries, then uses that to create a YOURLIB.{viewName} for every + other dictionary.view, eg: + + proc sql; + create view YOURLIB.columns as select * from dictionary.columns; + + Usage: + + libname demo "/lib/directory"; + %mp_dictionary(lib=demo) + + Or, to just create them in WORK: + + %mp_dictionary() + + If you'd just like to browse the dictionary data model, you can also check + out [this article](https://rawsas.com/dictionary-of-dictionaries/). + + @param lib= (WORK) The libref in which to create the views + +

Related Files

+ @li mp_dictionary.test.sas + + @version 9.2 + @author Allan Bowe + +**/ + +%macro mp_dictionary(lib=WORK)/*/STORE SOURCE*/; + %local list i mem; + proc sql noprint; + create view &lib..dictionaries as select * from dictionary.dictionaries; + select distinct memname into: list separated by ' ' from &lib..dictionaries; + %do i=1 %to %sysfunc(countw(&list,%str( ))); + %let mem=%scan(&list,&i,%str( )); + create view &lib..&mem as select * from dictionary.&mem; + %end; + quit; +%mend mp_dictionary; +/** @file @brief Returns all files and subdirectories within a specified parent @details When used with getattrs=NO, is not OS specific (uses dopen / dread). diff --git a/base/mp_createconstraints.sas b/base/mp_createconstraints.sas index c9d4d62..440a9df 100644 --- a/base/mp_createconstraints.sas +++ b/base/mp_createconstraints.sas @@ -18,11 +18,14 @@ %mp_deleteconstraints(inds=work.constraints,outds=dropped,execute=YES) %mp_createconstraints(inds=work.constraints,outds=created,execute=YES) - @param inds= The input table containing the constraint info - @param outds= a table containing the create statements (create_statement column) - @param execute= `YES|NO` - default is NO. To actually create, use YES. + @param inds= (work.mp_getconstraints) The input table containing the + constraint info + @param outds= (work.mp_createconstraints) A table containing the create + statements (create_statement column) + @param execute= (NO) To actually create, use YES. -

SAS Macros

+

Related Files

+ @li mp_getconstraints.sas @version 9.2 @author Allan Bowe @@ -30,7 +33,7 @@ **/ %macro mp_createconstraints(inds=mp_getconstraints - ,outds=mp_createconstraints + ,outds=work.mp_createconstraints ,execute=NO )/*/STORE SOURCE*/; @@ -64,4 +67,4 @@ data &outds; output; run; -%mend mp_createconstraints; \ No newline at end of file +%mend mp_createconstraints; diff --git a/base/mp_dictionary.sas b/base/mp_dictionary.sas new file mode 100644 index 0000000..5f0e7ed --- /dev/null +++ b/base/mp_dictionary.sas @@ -0,0 +1,50 @@ +/** + @file mp_dictionary.sas + @brief Creates a portal (libref) into the SQL Dictionary Views + @details Provide a libref and the macro will create a series of views against + each view in the special PROC SQL dictionary libref. + + This is useful if you would like to visualise (navigate) the views in a SAS + client such as Base SAS, Enterprise Guide, or Studio (or [Data Controller]( + https://datacontroller.io)). + + It works by extracting the dictionary.dictionaries view into + YOURLIB.dictionaries, then uses that to create a YOURLIB.{viewName} for every + other dictionary.view, eg: + + proc sql; + create view YOURLIB.columns as select * from dictionary.columns; + + Usage: + + libname demo "/lib/directory"; + %mp_dictionary(lib=demo) + + Or, to just create them in WORK: + + %mp_dictionary() + + If you'd just like to browse the dictionary data model, you can also check + out [this article](https://rawsas.com/dictionary-of-dictionaries/). + + @param lib= (WORK) The libref in which to create the views + +

Related Files

+ @li mp_dictionary.test.sas + + @version 9.2 + @author Allan Bowe + +**/ + +%macro mp_dictionary(lib=WORK)/*/STORE SOURCE*/; + %local list i mem; + proc sql noprint; + create view &lib..dictionaries as select * from dictionary.dictionaries; + select distinct memname into: list separated by ' ' from &lib..dictionaries; + %do i=1 %to %sysfunc(countw(&list,%str( ))); + %let mem=%scan(&list,&i,%str( )); + create view &lib..&mem as select * from dictionary.&mem; + %end; + quit; +%mend mp_dictionary; diff --git a/sasjs/sasjsconfig.json b/sasjs/sasjsconfig.json index ae89c0e..bcf3911 100644 --- a/sasjs/sasjsconfig.json +++ b/sasjs/sasjsconfig.json @@ -107,4 +107,4 @@ "contextName": "SAS Job Execution compute context" } ] -} \ No newline at end of file +} diff --git a/tests/base/mp_dictionary.test.sas b/tests/base/mp_dictionary.test.sas new file mode 100644 index 0000000..82c4d55 --- /dev/null +++ b/tests/base/mp_dictionary.test.sas @@ -0,0 +1,26 @@ +/** + @file + @brief Testing mp_dictionary.sas macro + +

SAS Macros

+ @li mp_dictionary.sas + @li mp_assert.sas + +**/ + +libname test (work); +%mp_dictionary(lib=test) + +proc sql; +create table work.compare1 as select * from test.styles; +create table work.compare2 as select * from dictionary.styles; + +proc compare base=compare1 compare=compare2; +run; +%put _all_; + +%mp_assert( + iftrue=(%mf_existds(&sysinfo)=0), + desc=Compare was exact, + outds=work.test_results +)