SUPPORT / SAMPLES & SAS NOTES
 

Support

Usage Note 24019: Is there a way to determine whether a format or informat is available for use, and whether it is supplied by SAS or user-defined?

DetailsAboutRate It

Beginning with SAS 9, the dictionary.formats table can be used to determine the source of a given format or informat. Along with the formats or informats that are supplied by SAS, any user-defined formats or informats that are located in a library that is listed in the FMTSEARCH= system option and in the WORK and LIBRARY libraries will be listed. A format or informat that is supplied by SAS will have a SOURCE value of B, and a format or informat that is user-defined will have a SOURCE value of C.

Here is the basic syntax:

  proc sql noprint;
   create table test
   as select libname, fmtname, source
   from dictionary.formats
   where source='B' or source='C' ;
   quit;

proc print;
run;

The following macro allows you to pass in the name of the format or informat as well as the type—F for format or I for informat. A message is written to the log that indicates whether or not it exists and its source:

%macro findfmt(fmt,type);

   proc sql noprint;
   create table test
   as select libname, fmtname, source, fmttype
   from dictionary.formats
   where fmtname="%upcase(&fmt)" and
         fmttype="%upcase(&type)";
   quit;

   %let dsid=%sysfunc(open(work.test));
   %let n=%sysfunc(attrn(&dsid,nobs));
   %let rc=%sysfunc(close(&dsid));

   %if %upcase(&type)=I %then %let msg_type=Informat;
   %if %upcase(&type)=F %then %let msg_type=Format;

   %if &n=0 %then
     %put &msg_type %upcase(&fmt) does not exist;

   %if &n>0 %then %do;
     data _null_;
       set test;
       if source="C" then
         put "&msg_type" +1 fmtname +1
             'is user-defined and exists in the'
              +1 libname +1 'library';
       if source="B" then
         put "&msg_type" +1 fmtname
       'is a SAS-supplied' +1 "&msg_type";
     run;
   %end;

%mend;

%findfmt(yymmdd,f)



Operating System and Release Information

Product FamilyProductSystemSAS Release
ReportedFixed*
SAS SystemBase SASAlln/a
* For software releases that are not yet generally available, the Fixed Release is the software release in which the problem is planned to be fixed.