/******************* URBAN INSTITUTE MACRO LIBRARY *********************
: Update_metadata_library
Macro: Registers metadata for a SAS library.
Description
: Open code
Use
: Peter Tatian
Author
***********************************************************************/
Update_metadata_library(
%macro lib_name= , /** Library reference **/
lib_desc= , /** Library description **/
meta_lib= , /** Library reference for metadata data sets **/
meta_pre= meta, /** Prefix for metadata data set names **/
quiet=N /** Suppress notes to LOG (Y/N) **/
);
/*************************** USAGE NOTES *****************************
:
SAMPLE CALLUpdate_metadata_library(
%lib_name=Sashelp,
lib_desc=SAS help library,
meta_lib=metadata
)
registers the library SASHELP with the metadata system*********************************************************************/
/*************************** UPDATE NOTES ****************************
01/02/04 Peter A. Tatian
10/29/04 Macro now will create _libs file if it does not exist.
09/06/05 Set OPTIONS OBS=MAX to avoid data loss when updating metadata.
09/29/10 PAT Delete temporary data set at end of macro execution.
*********************************************************************/
***** ***** ***** MACRO SET UP ***** ***** *****;
%
** Save current OBS= setting then set to MAX **;
%
Push_option( obs )
%
=max;
options obsNote_mput( macro=Update_metadata_library, msg=OPTIONS OBS set to MAX for metadata processing. )
%
***** ***** ***** ERROR CHECKS ***** ***** *****;
%
***** ***** ***** MACRO BODY ***** ***** *****;
%
** Create library record **;
&lib_name;
data _lib_
$ 32 LibDesc $ 400;
length Library
= upcase( "&lib_name" );
Library = "&lib_desc";
LibDesc
run;
** Create library metadata file if it does not exist **;
%if not %dataset_exists( &meta_lib..&meta_pre._libs ) %then %do;
Note_mput( macro=Update_metadata_library, msg=File &meta_lib..&meta_pre._libs does not exist - it will be created. )
%&meta_lib..&meta_pre._libs;
data &lib_name (obs=0);
set _lib_
run;
%end;
** Update library list **;
&meta_lib..&meta_pre._libs (compress=char);
data
&meta_lib..&meta_pre._libs _lib_&lib_name;
update
by Library;
run;
%if %upcase( &quiet ) ~= Y %then %do;
data _null_;&lib_name;
set _lib_
put;Note_put( macro=Update_metadata_file, msg="Update to Library metadata record:" )
%put (_all_) (= /);
/;
put
run;
%end;
run;
%Note_mput( macro=Update_metadata_library, msg=Library %upcase( &lib_name ) has been registered with the metadata system. )
** Delete temporary data set **;
=work memtype=(data) nolist nowarn;
proc datasets library&lib_name;
delete _lib_
quit;
:
%exit
***** ***** ***** CLEAN UP ***** ***** *****;
%
** Restore system options **;
%
Pop_option( obs )
%
Note_mput( macro=Update_metadata_library, msg=Macro exiting. )
%
%mend Update_metadata_library;
/************************ UNCOMMENT TO TEST ***************************
** Autocall macros **;
"K:\Metro\PTatian\UISUG\Uiautos";
filename uiautos =(uiautos sasautos);
options sasautosUpdate_metadata_library(
%lib_name=Work,
lib_desc=Test library,
meta_lib=work
)Update_metadata_library(
%lib_name=Sashelp,
lib_desc=SAS help library,
meta_lib=work
)=work memtype=(data);
proc datasets library
quit;File_info( data=Meta_libs, printobs=50, contents=n, stats= )
%/**********************************************************************/
Update Metadata for a Library
Purpose: Registers metadata for a SAS library.