<?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: Macro function to determine the column type (DATE, DATETIME, TIME) based on the SAS format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Determine-the-column-type-DATE-DATETIME-TIME-based-on-the-SAS/m-p/633609#M187956</link>
    <description>&lt;P&gt;Design question:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do you have two parameters posfmt and format= ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ut_fmt2type(posfmt,format=, lognote=N);

%local _this_fmt_type varfmt ;
/* allow positional and named parameter, prefer named parameter */
%let varfmt=%sysfunc(coalescec(&amp;amp;format.,&amp;amp;posfmt.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It looks like this is a positional parameter and a keyword parameter for the same parameter, so that a user can call in either manner.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But even if you define a parameter as positional, a user is still free to call it as a keyword parameter, which is a really nice feature of the macro language.&amp;nbsp; So I would think you could do this as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ut_fmt2type(format, lognote=N);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 20 Mar 2020 14:23:49 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2020-03-20T14:23:49Z</dc:date>
    <item>
      <title>Determine the column type (DATE, DATETIME, TIME) based on the SAS format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-the-column-type-DATE-DATETIME-TIME-based-on-the-SAS/m-p/633586#M187953</link>
      <description>&lt;P&gt;As of SAS release 9.4m3 it is possible to determine the "type" or category of a&amp;nbsp; SAS column by using the FMTINFO function.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Examples&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let fmttype=%sysfunc(fmtinfo(DATE,cat));   returned value: date
%let fmttype=%sysfunc(fmtinfo(DATETIME20.2,cat));  returned value: UNKNOWN&lt;BR /&gt;%let fmttype=%sysfunc(fmtinfo(DATETIME,cat));  returned value: datetime
&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Mar 2020 22:10:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-the-column-type-DATE-DATETIME-TIME-based-on-the-SAS/m-p/633586#M187953</guid>
      <dc:creator>DavePrinsloo</dc:creator>
      <dc:date>2020-03-20T22:10:43Z</dc:date>
    </item>
    <item>
      <title>Re: Macro function to determine the column type (DATE, DATETIME, TIME) based on the SAS format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-the-column-type-DATE-DATETIME-TIME-based-on-the-SAS/m-p/633609#M187956</link>
      <description>&lt;P&gt;Design question:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do you have two parameters posfmt and format= ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ut_fmt2type(posfmt,format=, lognote=N);

%local _this_fmt_type varfmt ;
/* allow positional and named parameter, prefer named parameter */
%let varfmt=%sysfunc(coalescec(&amp;amp;format.,&amp;amp;posfmt.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It looks like this is a positional parameter and a keyword parameter for the same parameter, so that a user can call in either manner.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But even if you define a parameter as positional, a user is still free to call it as a keyword parameter, which is a really nice feature of the macro language.&amp;nbsp; So I would think you could do this as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ut_fmt2type(format, lognote=N);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Mar 2020 14:23:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-the-column-type-DATE-DATETIME-TIME-based-on-the-SAS/m-p/633609#M187956</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2020-03-20T14:23:49Z</dc:date>
    </item>
    <item>
      <title>Re: Macro function to determine the column type (DATE, DATETIME, TIME) based on the SAS format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-the-column-type-DATE-DATETIME-TIME-based-on-the-SAS/m-p/633620#M187963</link>
      <description>I have been using SAS for 30+ years and I never knew that, Thanks!&lt;BR /&gt;I will modify the macro and repost. (But I need to leave to go to a drive-in Coronavirus test in 30 minutes, so that will have to wait!)</description>
      <pubDate>Fri, 20 Mar 2020 14:34:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-the-column-type-DATE-DATETIME-TIME-based-on-the-SAS/m-p/633620#M187963</guid>
      <dc:creator>DavePrinsloo</dc:creator>
      <dc:date>2020-03-20T14:34:07Z</dc:date>
    </item>
    <item>
      <title>Re: Macro function to determine the column type (DATE, DATETIME, TIME) based on the SAS format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-the-column-type-DATE-DATETIME-TIME-based-on-the-SAS/m-p/633621#M187964</link>
      <description>Good luck with your test!</description>
      <pubDate>Fri, 20 Mar 2020 14:34:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-the-column-type-DATE-DATETIME-TIME-based-on-the-SAS/m-p/633621#M187964</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2020-03-20T14:34:55Z</dc:date>
    </item>
    <item>
      <title>Re: Macro function to determine the column type (DATE, DATETIME, TIME) based on the SAS format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-the-column-type-DATE-DATETIME-TIME-based-on-the-SAS/m-p/633644#M187970</link>
      <description>&lt;P&gt;Why not just use the CAT type value from the FMTINFO() function?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro fmtcat(format);
%local i base;
%if %length(&amp;amp;format) %then %do;
  %let i=%sysfunc(verify(%qsysfunc(reverse(&amp;amp;format)),.0123456789));
  %if &amp;amp;i %then %let base=%sysfunc(substrn(&amp;amp;format,1,%length(&amp;amp;format)-&amp;amp;i+1));
  %else %let base=F;
  %sysfunc(fmtinfo(&amp;amp;base,cat))
%end;
%mend fmtcat;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Examples:&lt;/P&gt;
&lt;PRE&gt;195  %put %fmtcat(datetime24.3);
datetime
196  %put %fmtcat(time8.);
time
197  %put %fmtcat(best);
num
198  %put %fmtcat($char);
char
199  %put %fmtcat(32.);
num
200  %put %fmtcat(F);
num
201  %put %fmtcat($);
char
202  %put %fmtcat($10);
char
203  %put %fmtcat($10.);
char
204  %put %fmtcat();

205  %put %fmtcat(xyz);
UNKNOWN&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Mar 2020 15:39:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-the-column-type-DATE-DATETIME-TIME-based-on-the-SAS/m-p/633644#M187970</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-20T15:39:47Z</dc:date>
    </item>
  </channel>
</rss>

