/* Update history: 2-8-16: Adding code to use a custom formats catalog associated with the input directory. We edit the fmtearch sas option accordingly. This module is invoked by the wgenkey.sas module in /pub/applications/utils as a SAS/intrnet app. */ %global allmissing; %include '/pub/sas/macros/streamfile.sas'; %macro wgenkey; %global kv ki kq kf libname memname filetype sd ow ft; %if &ft ne %str() %then %let filetype=&ft; %if %superq(filetype) eq %str() %then %let filetype=&libname; *-- Build name of output html file in the /SAS_temp directory. ; %local htmlfile; %if %superq(filetype) ne %superq(libname) %then %let htmlfile=%str(/SAS_temp/keyvals/&filetype..&libname..&memname..&kv.vals.html); %else %let htmlfile=%str(/SAS_temp/keyvals/&libname..&memname..&kv.vals.html); *-- ow is an overwrite flag indicating to rewrite the file even if it exists. ; %if %nrbquote(&ow)=%str() %then %let ow=0; %if &ow eq 0 and %sysfunc(fileexist(&htmlfile)) %then %goto copyback; %local b1; *-- Used as pointer control to back up 1 space. ; %let b1=%str(+(-1)); %local vbar; %let vbar=%quote(|); filename htmlfile "&htmlfile"; libname &libname "/pub/data/&filetype/&sd" access=readonly; *-- Code added 9/03 and 10/08 to detect special cases where we need to load some temporary value-label formats. ; %if %nrbquote(&filetype)=popests and %index(&memname,casrh) %then %do; %include '/pub/data/popests/Tools/casrh_formats.sas'/nosource2; %end; %else %if %quote(&libname)=saipe and %index(&memname,sahie) %then %do; options fmtsearch = (saipe library work); %end; %else %do; *-- Generalize ability to access permanent SAS format codes unique to the filetype (added 2-8-16). ; %global existsfc; %let existsfc=0; data _null_; _existsfc = fileexist("/pub/data/&filetype/&sd"||"/formats.sas7bcat"); call symput('existsfc',put(_existsfc,1.)); stop; run; %if &existsfc %then %do; options fmtsearch=(&libname sasctlgs mable14 work); %end; %end; *-- If we get here the file does not exist or we want to rewrite it. ; %if %quote(&ki) eq &vbar %then %let ki=; %if %quote(&kf) eq &vbar %then %let kf=; %if %quote(&kq) eq &vbar %then %let kq=; %let key=%trim(&kv); %let fmat=%trim(&kf); %let qual=%trim(&kq); data _null_; file htmlfile; put "
'; %put &qual; %if &qual ne %str() %then %do; format &qual; put "(" &qual &b1 ")" @; %end; put "" &key &b1@; if _vallab ne " " then put "=" _vallab @; else put " " @; if nthisval gt 1 then put "(N=" nthisval &b1 ")" @; put '
'; end; if lastval then do; *--close out the table--; put '