<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: read catalog in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/read-catalog/m-p/341717#M63299</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Not sure this is what you are looking fo

/* T005670 Creating format source code from a format catalog -- John Groenfeld

inspired by
https://goo.gl/a25zs7
https://communities.sas.com/t5/SAS-Procedures/read-catalog/m-p/341691

HAVE A COMPILED FORMAT
======================

Contents of Catalog WORK.FORMATS

 #    Name       Type
--------------------------
 1    CITY       FORMATC

WANT
====
value  $city
       'BR1' = 'Birmingham UK'
       'BR2' = 'Plymouth UK'
       'BR3' = 'York UK'
       'US1' = 'Denver USA'
       'US2' = 'Miami USA'
       other = 'INCORRECT CODE'
;
run;quit;

WORKING CODE

      %utl_getfmt(outfile=d:/txt/city.txt,myfile=myformats,mytype=C,myfmt=CITY);


FULL SOLUTION
=============

proc datasets lib=work kill;
run;quit;

%symdel outfile myfmt myfile mytype / nowarn; * just in case;

* create and compile format $city;
proc format lib=work;
value  $city
       'BR1'   = 'Birmingham UK'
       'BR2'   = 'Plymouth UK'
       'BR3'   = 'York UK'
       'US1'   = 'Denver USA'
       'US2'   = 'Miami USA'
       other   = 'INCORRECT CODE'
;
run;quit;

proc format library=work cntlout=myformats;
run;quit;

%let pgm=utl_mkefmtsas;

/* this macro generates SAS program to re-create a user-defined format */
/* utiltity to delete sas code if you are rerunning */
%macro utl_fkil ( utlfkil ) / des="delete an external file";
    %local urc;
    %let urc = %sysfunc(filename(fname,%quote(&amp;amp;utlfkil)));
    %if &amp;amp;urc = 0 and %sysfunc(fexist(&amp;amp;fname)) %then
        %let urc = %sysfunc(fdelete(&amp;amp;fname));
    %let urc = %sysfunc(filename(fname,''));
  run;
%mend utl_fkil

;

/* create the format code */
%macro utl_getfmt(outfile=,myfmt=,myfile=,mytype=) ;

 /* This work is based on John Groenfeld macro in SAS-L         */
 /* Program will fail if format type is other than P C I N or J */
 /* I have tried to cover all kinds of format but I am no sure  */

 %put %sysfunc(ifc(%sysevalf(%superq(outfile)=,boolean),**** Please Provide output fileref for sas format code ****,));
 %put %sysfunc(ifc(%sysevalf(%superq(myfile )=,boolean),**** Please Provide an input format control dataset    ****,));
 %put %sysfunc(ifc(%sysevalf(%superq(mytype )=,boolean),**** Please Provide antype of format P C I N J only    ****,));
 %put %sysfunc(ifc(%sysevalf(%superq(myfmt  )=,boolean),**** Please Provide format name                        ****,));

 %let res= %eval
 (
     %sysfunc(ifc(%sysevalf(%superq(outfile)=,boolean),1,0))
   + %sysfunc(ifc(%sysevalf(%superq(myfile )=,boolean),1,0))
   + %sysfunc(ifc(%sysevalf(%superq(mytype )=,boolean),1,0))
   + %sysfunc(ifc(%sysevalf(%superq(myfmt  )=,boolean),1,0))
 );

 %if &amp;amp;res = 0 %then %do;

  /*
   /* tetcases without macro
   %let outfile  =outf;
   %let myfile   =fmt001;
   %let mytype   =P;
   %let myfmt    =SALARY;
  */

  data _null_ ;
      file "&amp;amp;outfile" mod ;
      set &amp;amp;myfile (where=(fmtname="&amp;amp;myfmt" and type="&amp;amp;mytype")) end=dne;
      /* global stuff */
      if   index(upcase(start),'*OTHER*' ) then start = compress(start,'*') ;
      if   index(upcase(end),  '*OTHER*' ) then end   = compress(start,'*') ;
      select (type);
          when ('P') do;
                       if _n_=1 then put  "picture " "&amp;amp;myfmt" ;
                       link other;
                       link quotelabel;
                       link noquotestart;
                       if upcase(start) ne 'OTHER' then do;
                          put '(mult=' mult best12. ;
                          if not missing(prefix)  then do ;
                            prefix=cats('"',prefix,'"');
                            put 'prefix=' prefix ;
                          end ;
                          if not missing(fill)  then do ;
                            fill=cats('"',fill,'"');
                            put 'fill=' fill;
                          end ;
                          put ')' ;
                       end;
          end;
          when ('C') do;
                       if _n_=1 then put  "value "  "$&amp;amp;myfmt";
                       link other;
                       link quotelabel;
                       link quotestart;
          end;
          when ('I') do;
                       if _n_=1 then put  "invalue " "&amp;amp;myfmt" ;
                       link other;
                       link noquotelabel;
                       link quotestart;
          end;
          when ('N') do;
                       if _n_=1 then put  "value "  "&amp;amp;myfmt" ;
                       link other;
                       link quotelabel;
                       link noquotestart;
          end;
          when ('J') do;
                       if _n_=1 then put  "invalue " "$&amp;amp;myfmt";
                       link other;
                       link quotelabel;
                       link quotestart;
          end;
      end;
      if dne then put ';';
      return;

      other:
        if   index(upcase(start),'*OTHER*' ) then start = compress(start,'*') ;
        if   index(upcase(end),  '*OTHER*' ) then end   = compress(start,'*') ;
      return;

      noquotestart:
        if start ne end then put start ' - ' end '= ' label;
        else put start '= ' label;
      return;

      quotestart:
        if upcase(start) ne 'OTHER'  then start = cats('"',start,'"');
        if upcase(end)   ne 'OTHER'  then end   = cats('"',end,  '"');
        if start ne end then put start ' - ' end '= ' label;
        else put start '= ' label;
      return;

      quotelabel:
        if hlo=:'LF' then label = cats('[',label,']') ;
        else              label = cats('"',label, '"');
      return;

      /* documentation purposes only */
      noquotelabel:
        label=label;
      return;
  run ;
 %end;
%mend utl_getfmt;

proc catalog cat=work.formats;
contents;
run;quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 16 Mar 2017 18:37:18 GMT</pubDate>
    <dc:creator>rogerjdeangelis</dc:creator>
    <dc:date>2017-03-16T18:37:18Z</dc:date>
    <item>
      <title>read catalog</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/read-catalog/m-p/341691#M63296</link>
      <description>&lt;P&gt;I am trying to open and view the code that is stored within a catalog.&amp;nbsp; I've been researching this all day and am at my wits end.&amp;nbsp; First I realized I needed to open an older version of SAS, I've tried proc catalog:&lt;/P&gt;
&lt;P&gt;proc catalog catalog=formats.formats;&lt;BR /&gt;contents;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but that information provides very little.&amp;nbsp; Also not very valuable:&lt;/P&gt;
&lt;P&gt;proc format /*fmtlib*/ library=formats.formats&lt;BR /&gt;cntlout=test;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have read about cport and cimport as well but I'm not sure what to do with that information.&amp;nbsp; I would like to open the file stored within the catalog formats, name = PORT.&amp;nbsp; Any help is appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 17:42:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/read-catalog/m-p/341691#M63296</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2017-03-16T17:42:25Z</dc:date>
    </item>
    <item>
      <title>Re: read catalog</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/read-catalog/m-p/341702#M63297</link>
      <description>&lt;P&gt;WHY is the cntlout dataset "not very valuable"? Please be very specific as there is everything about a format that you need to know in there though some of the values may take awhile to get used to interpretting, espcially indicator for such things a "other" or "_same_" and the multilabel and custom date formats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or are you looking for information about something other than formats that may be in that catalog?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 18:04:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/read-catalog/m-p/341702#M63297</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-16T18:04:43Z</dc:date>
    </item>
    <item>
      <title>Re: read catalog</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/read-catalog/m-p/341708#M63298</link>
      <description>&lt;P&gt;I'm looking for the formats that are in there, something that I can duplicate in my own proc format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I'm getting in cntout is fmtname, start end label min max etc.&amp;nbsp; I don't know what to do with any of that information.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I opened an older version of SAS, ran the code and am viewing the fields that the format runs on.&amp;nbsp;&amp;nbsp; This is what I was looking for, but it seems odd to me that it isn't easier to run some feature of proc catalog and get the macros that are stored within.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 18:10:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/read-catalog/m-p/341708#M63298</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2017-03-16T18:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: read catalog</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/read-catalog/m-p/341717#M63299</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Not sure this is what you are looking fo

/* T005670 Creating format source code from a format catalog -- John Groenfeld

inspired by
https://goo.gl/a25zs7
https://communities.sas.com/t5/SAS-Procedures/read-catalog/m-p/341691

HAVE A COMPILED FORMAT
======================

Contents of Catalog WORK.FORMATS

 #    Name       Type
--------------------------
 1    CITY       FORMATC

WANT
====
value  $city
       'BR1' = 'Birmingham UK'
       'BR2' = 'Plymouth UK'
       'BR3' = 'York UK'
       'US1' = 'Denver USA'
       'US2' = 'Miami USA'
       other = 'INCORRECT CODE'
;
run;quit;

WORKING CODE

      %utl_getfmt(outfile=d:/txt/city.txt,myfile=myformats,mytype=C,myfmt=CITY);


FULL SOLUTION
=============

proc datasets lib=work kill;
run;quit;

%symdel outfile myfmt myfile mytype / nowarn; * just in case;

* create and compile format $city;
proc format lib=work;
value  $city
       'BR1'   = 'Birmingham UK'
       'BR2'   = 'Plymouth UK'
       'BR3'   = 'York UK'
       'US1'   = 'Denver USA'
       'US2'   = 'Miami USA'
       other   = 'INCORRECT CODE'
;
run;quit;

proc format library=work cntlout=myformats;
run;quit;

%let pgm=utl_mkefmtsas;

/* this macro generates SAS program to re-create a user-defined format */
/* utiltity to delete sas code if you are rerunning */
%macro utl_fkil ( utlfkil ) / des="delete an external file";
    %local urc;
    %let urc = %sysfunc(filename(fname,%quote(&amp;amp;utlfkil)));
    %if &amp;amp;urc = 0 and %sysfunc(fexist(&amp;amp;fname)) %then
        %let urc = %sysfunc(fdelete(&amp;amp;fname));
    %let urc = %sysfunc(filename(fname,''));
  run;
%mend utl_fkil

;

/* create the format code */
%macro utl_getfmt(outfile=,myfmt=,myfile=,mytype=) ;

 /* This work is based on John Groenfeld macro in SAS-L         */
 /* Program will fail if format type is other than P C I N or J */
 /* I have tried to cover all kinds of format but I am no sure  */

 %put %sysfunc(ifc(%sysevalf(%superq(outfile)=,boolean),**** Please Provide output fileref for sas format code ****,));
 %put %sysfunc(ifc(%sysevalf(%superq(myfile )=,boolean),**** Please Provide an input format control dataset    ****,));
 %put %sysfunc(ifc(%sysevalf(%superq(mytype )=,boolean),**** Please Provide antype of format P C I N J only    ****,));
 %put %sysfunc(ifc(%sysevalf(%superq(myfmt  )=,boolean),**** Please Provide format name                        ****,));

 %let res= %eval
 (
     %sysfunc(ifc(%sysevalf(%superq(outfile)=,boolean),1,0))
   + %sysfunc(ifc(%sysevalf(%superq(myfile )=,boolean),1,0))
   + %sysfunc(ifc(%sysevalf(%superq(mytype )=,boolean),1,0))
   + %sysfunc(ifc(%sysevalf(%superq(myfmt  )=,boolean),1,0))
 );

 %if &amp;amp;res = 0 %then %do;

  /*
   /* tetcases without macro
   %let outfile  =outf;
   %let myfile   =fmt001;
   %let mytype   =P;
   %let myfmt    =SALARY;
  */

  data _null_ ;
      file "&amp;amp;outfile" mod ;
      set &amp;amp;myfile (where=(fmtname="&amp;amp;myfmt" and type="&amp;amp;mytype")) end=dne;
      /* global stuff */
      if   index(upcase(start),'*OTHER*' ) then start = compress(start,'*') ;
      if   index(upcase(end),  '*OTHER*' ) then end   = compress(start,'*') ;
      select (type);
          when ('P') do;
                       if _n_=1 then put  "picture " "&amp;amp;myfmt" ;
                       link other;
                       link quotelabel;
                       link noquotestart;
                       if upcase(start) ne 'OTHER' then do;
                          put '(mult=' mult best12. ;
                          if not missing(prefix)  then do ;
                            prefix=cats('"',prefix,'"');
                            put 'prefix=' prefix ;
                          end ;
                          if not missing(fill)  then do ;
                            fill=cats('"',fill,'"');
                            put 'fill=' fill;
                          end ;
                          put ')' ;
                       end;
          end;
          when ('C') do;
                       if _n_=1 then put  "value "  "$&amp;amp;myfmt";
                       link other;
                       link quotelabel;
                       link quotestart;
          end;
          when ('I') do;
                       if _n_=1 then put  "invalue " "&amp;amp;myfmt" ;
                       link other;
                       link noquotelabel;
                       link quotestart;
          end;
          when ('N') do;
                       if _n_=1 then put  "value "  "&amp;amp;myfmt" ;
                       link other;
                       link quotelabel;
                       link noquotestart;
          end;
          when ('J') do;
                       if _n_=1 then put  "invalue " "$&amp;amp;myfmt";
                       link other;
                       link quotelabel;
                       link quotestart;
          end;
      end;
      if dne then put ';';
      return;

      other:
        if   index(upcase(start),'*OTHER*' ) then start = compress(start,'*') ;
        if   index(upcase(end),  '*OTHER*' ) then end   = compress(start,'*') ;
      return;

      noquotestart:
        if start ne end then put start ' - ' end '= ' label;
        else put start '= ' label;
      return;

      quotestart:
        if upcase(start) ne 'OTHER'  then start = cats('"',start,'"');
        if upcase(end)   ne 'OTHER'  then end   = cats('"',end,  '"');
        if start ne end then put start ' - ' end '= ' label;
        else put start '= ' label;
      return;

      quotelabel:
        if hlo=:'LF' then label = cats('[',label,']') ;
        else              label = cats('"',label, '"');
      return;

      /* documentation purposes only */
      noquotelabel:
        label=label;
      return;
  run ;
 %end;
%mend utl_getfmt;

proc catalog cat=work.formats;
contents;
run;quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Mar 2017 18:37:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/read-catalog/m-p/341717#M63299</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-03-16T18:37:18Z</dc:date>
    </item>
  </channel>
</rss>

