/******************* URBAN INSTITUTE MACRO LIBRARY *********************
: Update_metadata_file
Macro: Registers metadata for a SAS data set.
Description
: Open code
Use
: Peter Tatian
Author
***********************************************************************/
Update_metadata_file(
%macro ds_lib= /** Data set library reference **/,
ds_lib_display= /** Library name displayed in metadata system (opt.) **/,
ds_name= /** Data set name **/,
creator= /** Name of data set creator **/,
creator_process= /** Name of data set creation process **/,
revisions= /** Description of latest data set revisions **/,
format=SAS /** Data set format **/,
restrictions=None /** Data set restrictions **/,
desc_stats=n sum mean std min max /** Descriptives to display in metadata **/,
max_fmt_vals=100 /** Maximum number of formatted values to display **/,
meta_lib= /** Library reference for metadata data sets **/,
meta_pre= meta /** Prefix for metadata data set names **/,
update_notify= /** FUNCTION DISABLED **/,
quiet=N, /** Suppress LOG messages **/
debug=N, /** Print extra debugging information **/
mprint=N, /** Print resolved macro code to LOG **/
add_exclude_fmts="", /** Additional user-defined formats to exclude from value pages **/
exclude_fmts=
"/$ASCII/$BIDI/$BINARY/$CHAR/$CPTDW/$CPTWD/$EBCDIC/$HEX/$KANJI/$KANJIX/$LOGVS/" ||
"/$LOGVSR/$MSGCASE/$OCTAL/$QUOTE/$REVERJ/$REVERS/$UCS2B/$UCS2BE/$UCS2L/$UCS2LE/$UCS2X/" ||
"/$UCS2XE/$UCS4B/$UCS4BE/$UCS4L/$UCS4LE/$UCS4X/$UCS4XE/$UESC/$UESCE/$UNCR/" ||
"/$UNCRE/$UPAREN/$UPARENE/$UPCASE/$UTF8X/$VARYING/$VSLOG/$VSLOGR/$/" ||
"/BEST/BINARY/COMMA/COMMAX/D/DATE/DATEAMPM/DATETIME/DAY/DDMMYY/" ||
"/DDMMYYB/DDMMYYC/DDMMYYD/DDMMYYN/DDMMYYP/DDMMYYS/" ||
"/DOLLAR/DOLLARX/DOWNAME/DTDATE/DTMONYY/DTWKDATX/DTYEAR/DTYYQC/" ||
"/E/EURDFDD/EURDFDE/EURDFDN/EURDFDT/EURDFDWN/EURDFMN/EURDFMY/EURDFWDX/EURDFWKX/EURFRATS/EURFRBEF/" ||
"/EURFRCHF/EURFRCZK/EURFRDEM/EURFRDKK/EURFRESP/EURFRFIM/EURFRFRF/EURFRGBP/EURFRGRD/EURFRHUF/" ||
"/EURFRIEP/EURFRITL/EURFRLUF/EURFRNLG/EURFRNOK/EURFRPLZ/EURFRPTE/EURFRROL/EURFRRUR/EURFRSEK/EURFRSIT/" ||
"/EURFRTRL/EURFRYUD/EURO/EUROX/EURTOATS/EURTOBEF/EURTOCHF/EURTOCZK/EURTODEM/EURTODKK/" ||
"/EURTOESP/EURTOFIM/EURTOFRF/EURTOGBP/EURTOGRD/EURTOHUF/EURTOIEP/EURTOITL/EURTOLUF/EURTONLG/" ||
"/EURTONOK/EURTOPLZ/EURTOPTE/EURTOROL/EURTORUR/EURTOSEK/EURTOSIT/EURTOTRL/EURTOYUD/" ||
"/FLOAT/FRACT/HDATE/HEBDATE/HEX/HHMM/HOUR/IB/IBR/IEEE/" ||
"/JULDAY/JULIAN/MINGUO/MMDDYY/" ||
"/MMDDYYB/MMDDYYC/MMDDYYD/MMDDYYN/MMDDYYP/MMDDYYS/" ||
"/MMSS/MMYY/" ||
"/MMYYC/MMYYD/MMYYN/MMYYP/MMYYS/" ||
"/MONNAME/MONTH/MONYY/NEGPAREN/NENGO/NLDATE/NLDATEMN/NLDATEW/NLDATEWN/NLDATM/NLDATMAP/" ||
"/NLDATMTM/NLDATMW/NLMNY/NLMNYI/NLNUM/NLNUMI/NLPCT/NLPCTI/NLTIMAP/NLTIME/NUMX/" ||
"/OCTAL/PD/PDJULG/PDJULI/PERCENT/PERCENTN/PIB/PIBR/PK/PVALUE/" ||
"/QTR/QTRR/RB/ROMAN/" ||
"/S370FF/S370FIB/S370FIBU/S370FPD/S370FPDU/S370FPIB/S370FRB/S370FZD/S370FZDL/S370FZDS/S370FZDT/S370FZDU/" ||
"/SSN/TIME/TIMEAMPM/TOD/VAXRB/WEEKDATE/WEEKDATX/WEEKDAY/WEEKU/WEEKV/WEEKW/" ||
"/WORDDATE/WORDDATX/WORDF/WORDS/YEAR/YEN/YYMM/" ||
"/YYMMC/YYMMD/YYMMN/YYMMP/YYMMS/" ||
"/YYMMDD/" ||
"/YYMMDDB/YYMMDDC/YYMMDDD/YYMMDDN/YYMMDDP/YYMMDDS/" ||
"/YYMON/" ||
"/YYQ/" ||
"/YYQC/YYQD/YYQN/YYQP/YYQS/" ||
"/YYQR/" ||
"/YYQRC/YYQRD/YYQRN/YYQRP/YYQRS/" ||
"/Z/ZD/"
/** SAS-defined formats to exlude from value pages **/
);
/*************************** USAGE NOTES *****************************
:
SAMPLE CALLUpdate_metadata_file(
%ds_lib=Dat,
ds_name=Shoes,
creator=SAS Institute,
creator_process=Shoes.sas,
revisions=New file.,
meta_lib=metadata
)in the metadata system
registers the data set Dat.Shoes *********************************************************************/
/*************************** UPDATE NOTES ****************************
01/02/04 Peter A. Tatian
09/02/04 Dealt with situation where data set has no formatted values
Clean up temporary data sets at end of macro10/28/04 Checks that library is registered in metadata system.
If not, exits macro without processing file.10/29/04 Macro will now create _files, _vars, _fval, and _history
if they do not already exist.
metadata files 11/10/04 Added max_fmt_vals= option to limit number of formatted values
for a variable (def=100/max=2000000).
written to metadata 11/11/04 NOTE printed to log when max. no. formatted values surpassed.
11/15/04 Added support for SAS data set views.
12/20/04 Setting desc_stats= to blank will suppress descriptive stats
for numeric variables.
03/25/05 Implemented update_notify= option.
05/06/05 Added file sorted by info to metadata.
09/06/05 Set OPTIONS OBS=MAX to avoid data loss when updating metadata.
=Y.
Set NOMPRINT unless MPRINT12/06/06 Added ADD_EXCLUDE_FMTS= option to exclude additional,
-specified formats.
user03/08/08 Updated excluded format list to all SAS 9.2 formats.
06/09/10 Write note to LOG for each email notification.
09/29/10 Corrected problem with long data set names.
02/23/11 PAT Added declaration for local macro vars.
* to _fvar*.
Changed name of local macro vars fvar10/12/11 PAT Increased length of FileRevisions to 500.
11/09/13 PAT Revised for use with new SAS server setup.
=.
Added ds_lib_display= functionality.
Removed update_notify07/28/17 PAT Will now properly register empty data sets or
data sets without numeric variables. for datetime and time vars.
Added support *********************************************************************/
***** ***** ***** MACRO SET UP ***** ***** *****;
%
%local sortvars SAS_DATASET_VIEW lib_exists ds_name25 allfvar i em num_fval_vars num_obs num_vars;
= "SASDSV";
%let SAS_DATASET_VIEW
** If not specified, use ds_lib value as ds_lib_display **;
%
%if &ds_lib_display = %then %let ds_lib_display = &ds_lib;
** Save current MPRINT setting and reset based on MPRINT= parameter **;
%
Push_option( mprint )
%
%if %mparam_is_yes( &mprint ) %then %do;
options mprint;
%end;%else %do;
options nomprint;
%end;
** Shorter file name for temporary data sets **;
%
%if %length( &ds_name ) > 25 %then %let ds_name25 = %substr( &ds_name, 1, 25 );
%else %let ds_name25 = &ds_name;
** Force step boundary **;
%
run;
** Save current OBS= setting then set to MAX **;
%
Push_option( obs )
%
=max;
options obsNote_mput( macro=Update_metadata_file, msg=OPTIONS OBS set to MAX for metadata processing. )
%
***** ***** ***** ERROR CHECKS ***** ***** *****;
%
** Check for existence of library metadata file **;
%
%if not %Dataset_exists( &meta_lib..&meta_pre._libs, quiet=n ) %then %do;
Err_mput( macro=Update_metadata_file, msg=File &meta_lib..&meta_pre._libs does not exist. )
%
%goto exit_err;
%end;
** Check that library is registered **;
%
Data_to_format(
%FmtName=$libchk,
inDS=&meta_lib..&meta_pre._libs,
value=upcase( Library ),
label="Y",
otherlabel="N",
print=N )
data _null_;symput( 'lib_exists', put( upcase( "&ds_lib_display" ), $libchk. ) );
call
run;
%if &lib_exists = N %then %do;
Err_mput( macro=Update_metadata_file, msg=Library &ds_lib_display is not registered in the metadata system. )
%
%goto exit_err;
%end;
** Check for existence of data set to be registered **;
%
%if not ( %Dataset_exists( &ds_lib..&ds_name, quiet=n, memtype=data ) or
%Dataset_exists( &ds_lib..&ds_name, quiet=n, memtype=view ) ) %then %do;
Err_mput( macro=Update_metadata_file, msg=The data set &ds_lib..&ds_name does not exist. )
%
%goto exit_err;
%end;
***** ***** ***** MACRO BODY ***** ***** *****;
%
** Get data set contents **;
=&ds_lib..&ds_name out=_cnts_&ds_name25 noprint;
proc contents data
%if %mparam_is_yes( &debug ) %then %do;
=_cnts_&ds_name25;
proc contents data"File = _cnts_&ds_name25";
title2 =_cnts_&ds_name25;
proc print data
%end;
** Check for observations **;
proc sql noprint;count(*) into :num_obs
select &ds_lib..&ds_name;
from
quit;
%if %length( &desc_stats ) > 0 %then %do;
** Check for numeric variables **;
proc sql noprint;count( name ) into :num_vars
select
from dictionary.columnsupcase(libname)="%upcase(&ds_lib)" and upcase(memname)="%upcase(&ds_name)" and upcase(type) = "NUM";
where
quit;
%if &num_vars > 0 and &num_obs > 0 %then %do;
** Get descriptive statistics for numeric variables **;
Compile_num_desc( stats=&desc_stats, ds_lib=&ds_lib, ds_name=&ds_name )
%
%end;%else %do;
%note_mput( macro=Update_metadata_file, msg=No numeric variables in data set %upcase(&ds_lib..&ds_name). )
%end;
%end;
** Get list of sorted by variables **;
proc sql noprint;_sortvars (compress=no) as
create table
select name, sortedby &ds_name25 (where=(sortedby > 0))
from _cnts_
order by sortedby
;
select name :sortvars separated by ', '
into
from _sortvars
;
** Merge contents and descriptive stats files **;
=_cnts_&ds_name25;
proc sort data
by name;
&ds_name25;
data _info_
%if %length( &desc_stats ) > 0 and &num_vars > 0 and &num_obs > 0 %then %do;
&ds_name25 &_compile_num_desc_out (rename=(_name_=name));
merge _cnts_
by name;
: ;
format _desc_
%end;%else %do;
&ds_name25;
set _cnts_
%end;
run;
=_info_&ds_name25;
proc sort data
by varnum;
run;
%if %mparam_is_yes( &debug ) %then %do;
=_info_&ds_name25 (obs=10);
proc print data"File = _info_&ds_name25";
title2
run;
%end;
** Process and validate metadata in contents **;
** Create new records for updating metadata files **;
data
/* File record */
&ds_name25
_f_keep=libname_display memname memlabel nobs modate MetadataUpdated FileCreator FileProcess
(
FileFmt FileRestrict FileSortedByrename=(libname_display=Library memname=FileName memlabel=FileDesc nobs=NumObs
modate=FileUpdated))
/* History record */
&ds_name25
_h_keep=libname_display memname modate MetadataUpdated FileCreator FileProcess
(
FileRevisionsrename=(libname_display=Library memname=FileName modate=FileUpdated))
/* Variable records */
&ds_name25
_v_keep=libname_display memname varnum name VarNameUC label VarType length format
(
ListFmtVals%if %length( &desc_stats ) > 0 and &num_vars > 0 and &num_obs > 0 %then %do;
:
_desc_
%end;rename=(libname_display=Library memname=FileName varnum=VarOrder name=VarName label=VarDesc
length=VarLen format=VarFmt))
;
$ 32; ** Force resize of libname variable **;
length libname_display
"%upcase( &ds_lib_display )";
retain libname_display
&ds_name25;
set _info_
length $ 1
VarType $ 32
VarNameUC FileFmt $ 80
FileCreator FileProcess $ 250
FileRestrict FileSortedBy $ 500
FileRevisions 3
ListFmtVals
;
** Process file-level data (first obs.) **;
if _n_ = 1 then do;
if memlabel = "" then do;
warn_put( macro=Update_metadata_file, msg="Data set &ds_name not labeled." )
%
end;
= datetime();
MetadataUpdated
format MetadataUpdated datetime16.;
%if &format = SAS %then %do;
if Engine = &SAS_DATASET_VIEW then
= "SAS/View";
FileFmt else
= "SAS/" || trim( Engine );
FileFmt
%end;%else %do;
= "&format";
FileFmt
%end;
= "&creator";
FileCreator = "&creator_process";
FileProcess = "&revisions";
FileRevisions = "&restrictions";
FileRestrict = lowcase( "&sortvars" );
FileSortedBy
&ds_name25;
output _f_
&ds_name25;
output _h_
end;
** Process variable-level data (all obs.) **;
if label = "" then do;
Warn_put( macro=Update_metadata_file, msg="Variable " name " in data set &ds_name not labeled." )
%
end;
if type = 1 then VarType = "N";
else if type = 2 then VarType = "C";
= upcase( name );
VarNameUC
if format ~= "" and &num_obs > 0 and
index( %upcase(&exclude_fmts||&add_exclude_fmts), compress( "/" || format || "/" ) )
not
then= 1;
ListFmtVals else
= 0;
ListFmtVals
&ds_name25;
output _v_
label= "Data set name"
memname = "Library name"
libname_display = "Data set format"
FileFmt = "Name of data set creator"
FileCreator = "Name or description of data set creation process"
FileProcess = "Revisions since previous data set version"
FileRevisions = "Type of data set restrictions"
FileRestrict = "List of variables indicating data set sort order (if sorted)"
FileSortedBy = "Date metadata was updated"
MetadataUpdated = "Formatted values listed in metadata (1=Yes)"
ListFmtVals = "Variable name (uppercase, for sorting)"
VarNameUC = "Variable type (C/N)"
VarType
;
run;
=_v_&ds_name25;
proc sort data
by Library FileName VarNameUC;
%if %mparam_is_yes( &debug ) %then %do;
=_f_&ds_name25;
proc print data$40.;
format FileRestrict "_f_&ds_name25";
title2
=_h_&ds_name25;
proc print data"_h_&ds_name25";
title2
=_v_&ds_name25;
proc print data"_v_&ds_name25";
title2
run;
%end;
** Create data set with frequencies for formatted variables **;
data _null_;
&ds_name25 end=eof;
set _v_
if ListFmtVals then do;
+ 1;
count symput( '_fvar' || left( count ), VarName );
call
end;
if eof then call symput( 'num_fval_vars', count );
run;
= ;
%let allfvar
*options mprint symbolgen mlogic;
%if &num_fval_vars > 0 and &num_obs > 0 %then %do;
%do i = 1 %to &num_fval_vars;
= &allfvar &&_fvar&i;
%let allfvar
%end;
%if %mparam_is_yes( &debug ) %then %do;
=&num_fval_vars;
%put num_fval_vars=&allfvar;
%put allfvar
%end;
Freq_table( in_data = &ds_lib..&ds_name,
%var_list = &allfvar,
out_data = _fvals_&ds_name25 )
%if %mparam_is_yes( &debug ) %then %do;
=_fvals_&ds_name25;
proc print data"File = _fvals_&ds_name25";
title2
run;
%end;
data
/* Formatted values record */
&ds_name25
_fv_keep=Library FileName Variable VarNameUC Frequency Value FmtValue
(
MaxFmtValsrename=(Variable=VarName))
;
$ 32; ** Force resize of variable name variable **;
length variable
$ 32;
length Library FileName VarNameUC
4;
length MaxFmtVals
"%upcase(&ds_lib_display)" FileName "%upcase(&ds_name)";
retain Library
&ds_name25;
set _fvals_
by Variable notsorted;
if first.Variable then count = 0;
+ 1;
count
= upcase( Variable );
VarNameUC
if count = &max_fmt_vals and not last.Variable then do;
= &max_fmt_vals;
MaxFmtVals Note_put( macro=Update_metadata_file,
%msg="Maximum no. of formatted values (&max_fmt_vals) reached for var. " VarNameUC " Additional values will be suppressed in metadata." )
end;
if count <= &max_fmt_vals then output;
label= "Data set name"
FileName = "Library name"
Library = "Variable name (uppercase, for sorting)"
VarNameUC = "Frequency count for value"
Frequency = "If not missing, maximum number of formatted values for metadata was surpassed"
MaxFmtVals
;
run;
=_fv_&ds_name25;
proc sort data
by Library FileName VarNameUC Value;
run;
%if %mparam_is_yes( &debug ) %then %do;
=_fv_&ds_name25;
proc print data"File = _fv_&ds_name25";
title2
run;
%end;
%end;
** Create metadata files if they do not exist **;
%if not %dataset_exists( &meta_lib..&meta_pre._files ) %then %do;
Note_mput( macro=Update_metadata_file, msg=File &meta_lib..&meta_pre._files does not exist - it will be created. )
%&meta_lib..&meta_pre._files;
data &ds_name25 (obs=0);
set _f_
run;
%end;
%if not %dataset_exists( &meta_lib..&meta_pre._history ) %then %do;
Note_mput( macro=Update_metadata_file, msg=File &meta_lib..&meta_pre._history does not exist - it will be created. )
%&meta_lib..&meta_pre._history;
data &ds_name25 (obs=0);
set _h_
run;
%end;
%if not %dataset_exists( &meta_lib..&meta_pre._vars ) %then %do;
Note_mput( macro=Update_metadata_file, msg=File &meta_lib..&meta_pre._vars does not exist - it will be created. )
%&meta_lib..&meta_pre._vars;
data &ds_name25 (obs=0);
set _v_
run;
%end;
%if not %dataset_exists( &meta_lib..&meta_pre._fval ) %then %do;
%if %dataset_exists( _fv_&ds_name25 ) %then %do;
Note_mput( macro=Update_metadata_file, msg=File &meta_lib..&meta_pre._fval does not exist - it will be created. )
%&meta_lib..&meta_pre._fval;
data &ds_name25 (obs=0);
set _fv_
run;
%end;
%end;
** Update file record in metadata **;
&meta_lib..&meta_pre._files (compress=char);
data
&meta_lib..&meta_pre._files _f_&ds_name25 updatemode=nomissingcheck;
update
by Library FileName;
run;
** Update file history record in metadata **;
&meta_lib..&meta_pre._history (compress=char);
data
&meta_lib..&meta_pre._history _h_&ds_name25;
update
by Library FileName descending FileUpdated;
run;
** Update variable records in metadata **;
data _vars;
&meta_lib..&meta_pre._vars;
set
if library = "%upcase( &ds_lib_display )" and FileName = "%upcase( &ds_name )"
then delete;
run;
&meta_lib..&meta_pre._vars (compress=char);
data
&ds_name25 updatemode=nomissingcheck;
update _vars _v_
by Library FileName VarNameUC;
run;
** Update formatted variable value records in metadata **;
%if %dataset_exists( &meta_lib..&meta_pre._fval ) %then %do;
data _fvalues;
&meta_lib..&meta_pre._fval;
set
if library = "%upcase( &ds_lib_display )" and FileName = "%upcase( &ds_name )"
then delete;
run;
%if &num_fval_vars > 0 and &num_obs > 0 %then %do;
&meta_lib..&meta_pre._fval (compress=char);
data
&ds_name25 updatemode=nomissingcheck;
update _fvalues _fv_
by Library FileName VarNameUC Value;
run;
%end;%else %do;
&meta_lib..&meta_pre._fval (compress=char);
data
set _fvalues;
run;
%end;
%end;
** Print updated metadata to log (unless Quiet=Y) **;
%if %upcase( &quiet ) ~= Y %then %do;
data _null_;&ds_name25;
set _f_
put;Note_put( macro=Update_metadata_file, msg="Update to File metadata record:" )
%put (_all_) (= /);
/;
put
run;
data _null_;&ds_name25;
set _h_
put;Note_put( macro=Update_metadata_file, msg="Update to File History metadata record:" )
%put (_all_) (= /);
/;
put
run;
data _null_;
&ds_name25 end=eof;
set _v_
if eof then do;
put;Note_put( macro=Update_metadata_file, msg="Update to Variables metadata record:" )
%= / FileName= ;
put Library"NumberVariables=" _n_;
put /;
put
end;
run;
%if &num_fval_vars > 0 and &num_obs > 0 %then %do;
data _null_;
&ds_name25;
set _fv_
by VarNameUC;
+ 1;
count
if _n_ = 1 then do;
put;Note_put( macro=Update_metadata_file, msg="Update to Formatted Values metadata record:" )
%= / FileName= ;
put Library
end;
if last.VarNameUC then do;
= @;
put VarName" / NumberValues=" count;
put /;
put = 0;
count
end;
run;
%end;%else %do;
%put;Note_mput( macro=Update_metadata_file, msg=No Formatted Values updated. )
%
%end;
%end;
%if %mparam_is_yes( &debug ) %then %do;
=&meta_lib..&meta_pre._files;
proc contents data"File = &meta_lib..&meta_pre._files";
title2
=&meta_lib..&meta_pre._files;
proc print data$40.;
format FileRestrict "File = &meta_lib..&meta_pre._files";
title2
=&meta_lib..&meta_pre._history;
proc contents data"File = &meta_lib..&meta_pre._history";
title2
=&meta_lib..&meta_pre._history;
proc print data"File = &meta_lib..&meta_pre._history";
title2
=&meta_lib..&meta_pre._vars;
proc contents data"File = &meta_lib..&meta_pre._vars";
title2
=&meta_lib..&meta_pre._vars;
proc print data"File = &meta_lib..&meta_pre._vars";
title2
=&meta_lib..&meta_pre._fval;
proc contents data"File = &meta_lib..&meta_pre._fval";
title2
=&meta_lib..&meta_pre._fval noobs;
proc print data
by Library Filename VarNameUC;"File = &meta_lib..&meta_pre._fval";
title2
run;
%end;
***** ***** ***** CLEAN UP ***** ***** *****;
%
** Clean up all temporary files **;
=WORK memtype=(data) nolist nowarn;
proc datasets library: _desc_: _fvals_: _fvalues _f_: _fv_: _h_: _v_:
delete _cnts_: _vars _sortvars;
_info_
quit;
run;
Note_mput( macro=Update_metadata_file, msg=Data set &ds_lib_display..&ds_name successfully registered with metadata system. )
%
%goto exit;
:
%exit_err
Err_mput( macro=Update_metadata_file, msg=Data set &ds_lib_display..&ds_name was not registered with metadata system. )
%
%goto exit;
:
%exit
** Restore system options **;
%
Pop_option( obs )
%Pop_option( mprint )
%
Note_mput( macro=Update_metadata_file, msg=Macro Update_metadata_file() exiting. )
%
%mend Update_metadata_file;
/************************ UNCOMMENT TO TEST ***************************
** Autocall macros **;
"K:\Metro\PTatian\UISUG\Uiautos";
filename uiautos =(uiautos sasautos) noxwait;
options sasautos** Set up and clear test folder **;
"md d:\temp\Update_metadata_file_test";
x "del /q d:\temp\Update_metadata_file_test\*.*";
x "d:\temp\Update_metadata_file_test\";
libname test proc format library=work;
value $region
"Africa" = "~Africa"
"Asia" = "~Asia"
"Canada" = "~Canada"
"Central America/Caribbean" = "~Central America/Caribbean"
"Eastern Europe" = "~Eastern Europe"
"Middle East" = "~Middle East"
"Pacific" = "~Pacific"
"South America" = "~South America"
"United States" = "~United States"
"Western Europe" = "~Western Europe";
data Test.Shoes;
set Sashelp.shoes;
dvar = date();
dtvar = datetime();
tvar = time();
label
dvar = "Date testing variable"
dtvar = "Datetime testing variable"
tvar = "Time testing variable";
format region $region.;
format dvar mmddyy10. dtvar datetime. tvar time.;
run;
data Test.Shoes_nonum (label="Shoes data set without numeric vars");
set Test.shoes;
keep _character_;
run;
data Test.Shoes_empty (label="Shoes data set with no observations");
set Test.shoes (obs=0);
run;
%File_info( data=Test.shoes, freqvars=region )
%File_info( data=Test.shoes_nonum, stats= )
%File_info( data=Test.shoes_empty, stats= )
** Testing for reporting error when trying to register a data set to an unregistered library **;
%Update_metadata_file(
ds_lib=Test,
ds_name=Shoes,
creator=SAS Institute,
creator_process=SAS Institute,
revisions=Test file.,
meta_lib=Test
)
** Register library **;
%Update_metadata_library(
lib_name=Test,
lib_desc=Test library,
meta_lib=Test
)
** Register data set **;
%Update_metadata_file(
ds_lib=Test,
ds_name=Shoes,
creator=SAS Institute,
creator_process=SAS Institute,
revisions=Test file SHOES.,
meta_lib=Test,
mprint=y
)
** Test data set without numeric variables **;
%Update_metadata_file(
ds_lib=Test,
ds_name=Shoes_nonum,
creator=SAS Institute,
creator_process=SAS Institute,
revisions=Test file SHOES_NONUM.,
meta_lib=Test,
mprint=y
)
** Test data set with no observations **;
%Update_metadata_file(
ds_lib=Test,
ds_name=Shoes_empty,
creator=SAS Institute,
creator_process=SAS Institute,
revisions=Test file SHOES_EMPTY.,
meta_lib=Test,
mprint=y
)
proc datasets library=Test memtype=(data);
quit;
%File_info( data=Test.Meta_files, printobs=50, contents=n, stats= )
%File_info( data=Test.Meta_vars, printobs=50, contents=n, stats= )
%File_info( data=Test.Meta_fval, printobs=50, contents=n, stats= )
%File_info( data=Test.Meta_history, printobs=50, contents=n, stats= )
/**********************************************************************/
Update Metadata for a File
Purpose: Registers metadata for a SAS data set.