In many SAS environment the SAS Options FMTSEARCH path can concatenate a list of SAS catalogs where shared formats can be acccessed and used. But what if there are duplicate formats across multiple catalogs. This macro uses the value of FMTSEARCH to extract all formats stored across the catalogs listed and creates a dataset containing the list, including highlighting any potential issues.
See %fmtsearch_contents(attached), sample output below highlighting potential duplicate formats
NOTE : Also uses %setoptions (attached) AND %setdates macro (see link below - used to identify formats not recently updated)
Wouldn't it be easier to just use SASHELP.VCATALG view?
data formats ;
retain catlist "%sysfunc(getoption(fmtsearch))";
length order level active dup 8 objtype $8 fmtname $32 ;
set sashelp.vcatalg (drop=memtype objdesc alias);
where objtype in ('FORMAT' 'FORMATC' 'INFMT' 'INFMTC');
order = findw(catlist,catx('.',libname,memname),'( )','ET')
+ findw(catlist,libname,'( )','ET')*(memname='FORMATS')
;
if order ;
fmtname=objname;
if index(objtype,'C') then fmtname='$'||fmtname;
drop catlist objname;
rename objtype=fmttype;
run;
proc sort data=formats;
by fmttype fmtname order level ;
run;
data formats;
set formats;
by fmttype fmtname;
active = first.fmtname;
dup = not (first.fmtname and last.fmtname);
run;
So if you setup this environment:
proc format lib=work.formats;
value $sex 'M'='Male' 'F'='Female';
value age low-12 = 'Pre-teen' 13-19='Teen';
picture abc (multilabel)
1000='9,999'
1000='9999';
run;
proc format lib=work.myfmt;
value $sex 'm'='male' 'f'='female';
invalue $sex (upcase) 'M'='Male' 'F'='Female';
invalue male (upcase) 'M'=1 'F'=0 other=.;
run;
options fmtsearch=(WORK LIBRARY WORK.MYFMT);
You get this result from the query.
Definitely a much simpler and more elegant solution from Tom to achieve the same result. I tip my hat 🙂
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.