/******************************************************************** * NAME: metahtml SYSTEM: MSCDC PGMR: Struthers/Blodgett * * FUNCTION: From specified SAS set, generate a Metadata.html * * file with variable names and initial text (labels). * * is optional prefix used when specific=1 specified * * indicating the metadata is for that specific data set, not * * generic for any set in the directory. * * NOTES: Macrofied and adapted by jgb from inital code by jws. * ********************************************************************/ %GLOBAL REVDATE; %LET REVDATE=17Sep01; *<----DATE OF LAST REVISION; *--modified to run on mcdc with different default path--; /********************************************************************/ /* BEGIN MACRO DEFINITION */ /********************************************************************/ %MACRO metahtml( filetype=, /* filetype can explictly specified instead of path. Then macro will assume path has value of /pub/data/&filetype */ path=, /* semi-required parm. (Can be implied from filetype). Specifies UNIX directory where output file is to be written, and where default input data set is located */ subdir=, /* If input data is in a subdirectory of path then specify it here. Default input data library is then &path/&subdir */ setin=, /* Required parm. Input SAS data set name - 2ND LEVEL ONLY*/ notext=0, /* specify notext=1 if you do NOT want to use SAS variable labels as the initial text to describe each variable */ specific=0, /* specify a value of 1 to cause the output to be named for the specific input data set. Default is to write output to &path/Metadata.html. If this option is specified then output is written to &path/&setin..Metadata.html */ replace=0, /* if the output file (Metadata) already exists then you must specify replace=1 to overwrite it. This prevents accidental overwriting of previous, customized html files. Added 12-00 */ keywords=, /* inserted in meta tag in header portion of page */ list=0, /* specify list=1 to have the output file listed on print file */ debug=0); /* END */ %PUT %STR( ); %PUT ***************************************************************; %put * metahtml macro Rev &revdate begin execution *; %put * Missouri State Census Data Center *; %PUT ***************************************************************; %PUT %STR( ); %local libin fileout err label; %let err=0; %if %quote(&path) eq %then %do; %if %quote(&filetype) ne %then %let path=/pub/data/&filetype; %else %do; %put ****metahtml required parm "path" was not specified****; %let err=1; %end; %end; %let libin=&path; %if %quote(&setin) eq %then %do; %put ****metahtml required parm "setin" was not specified****; %let err=1; %end; %if &err %then %do; %put ****metahtml aborting due to errors*****; %goto endmac; %end; %if %quote(&subdir) ne %then %let libin=&path%str(/)&subdir; %if &specific %then %let fileout=&libin/&setin..Metadata.html; %else %let fileout=&libin/Metadata.html; %if &replace=0 %then %do; data _null_; if fileexist("&fileout") then call symput('err','1'); run; %if &err %then %do; %put ****Output file &fileout already exists.; %put ****You must specify "replace=1" parm if you want metahtml ; %put ****to write over an existing file.; %put **** Macro excecution aborting. ****; %goto endmac; %end; %end; %if ¬ext %then %let label=; %else %let label=%str('
' label) ; libname _libin "&libin"; filename _metaout "&fileout"; proc contents data=_libin.&setin memtype=data noprint out=_contnts;run; proc sort data=_contnts;by varnum;run; data _null_;file _metaout;retain back -1; set _contnts end=eof; if _n_=1 then do; put ' '; put ''; put ''; %if &specific=0 %then %let t2=Datasets with filetype=&filetype ; %else %let t2=dataset &path/&setin; %let title="Metadata for &t2"; put &title ""; put ''; put ''; put "

" &title "

"; put 'Click on variable name to scroll to its description:

'; end; name=lowcase(name); put '' name '|'; if eof then do; put ''; end; run; data _null_;file _metaout mod;retain back -1; set _contnts end=eof; if _n_=1 then do; put ''; * put '

';
 end;
  name=lowcase(name);
 put '

' name +back ''; put &label; *<--local parm resolves to either "label" or null-value; if eof then do; put '

'; put ''; put ''; put 'Missouri Census Data Center

'; put "MCDC file: &fileout
"; put "Metahtml run date: &sysdate" ; put ''; put ''; end; run; libname _libin clear; %if &list %then %do; title5 "HTML Output for Dataset &libin..&setin"; data _null_;infile _metaout;file print; input; put _infile_; run; title5 ; %end; %endmac: %MEND metahtml;