BookmarkSubscribeRSS Feed

%fmtsearch_contents Macro - Lists of ALL SAS formats in FMTSEARCH path

Started ‎03-06-2025 by
Modified ‎03-06-2025 by
Views 1,110

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

 

davidlogan_0-1738829425405.png

 

 

NOTE : Also uses %setoptions (attached) AND  %setdates macro (see link below - used to identify formats not recently updated)

 

https://communities.sas.com/t5/SAS-Communities-Library/setdates-macro-generates-SAS-date-macro-varia...

Comments
Tom

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.

Tom_0-1741279049466.png

 

Definitely a much simpler and more elegant solution from Tom to achieve the same result. I tip my hat 🙂

Contributors
Version history
Last update:
‎03-06-2025 08:47 AM
Updated by:

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

SAS AI and Machine Learning Courses

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.

Get started

Article Labels
Article Tags