<?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: extract year from macro format date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/extract-year-from-macro-format-date/m-p/550491#M152846</link>
    <description>&lt;P&gt;&lt;EM&gt;&amp;gt;sometime if the input date is not in that format, it doesn't work.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. If it's not in this format then this won't work&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;%let edate=%sysfunc(inputn(&amp;amp;end_dt, yymmdd10.), date9.);&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2. What other strings formats do you expect?&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 12 Apr 2019 03:14:03 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2019-04-12T03:14:03Z</dc:date>
    <item>
      <title>extract year from macro format date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-year-from-macro-format-date/m-p/550484#M152841</link>
      <description>&lt;P&gt;I tried to extract year and month from macro function such as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%Get_year(2018-12-31);&lt;/P&gt;&lt;P&gt;&amp;nbsp;can return&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;amp;year=2018&lt;/P&gt;&lt;P&gt;&amp;amp;month=12&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the following syntax but it return year 1967 instead of 2018 after calling the function&amp;nbsp;%Get_year(2018-12-31);&lt;/P&gt;&lt;P&gt;%macro Get_year(end_dt);&lt;/P&gt;&lt;P&gt;%let edate=%sysfunc(inputn(&amp;amp;end_dt, yymmdd10.), date9.);&lt;BR /&gt;%put &amp;amp;edate.;&lt;BR /&gt;%let policy_dt = %sysfunc(intnx(month,&amp;amp;end_dt.,+30,end));&lt;BR /&gt;%put &amp;amp;policy_dt.;&lt;BR /&gt;%let year0 =%sysfunc(year(&amp;amp;policy_dt.));&lt;BR /&gt;%let year1 =%sysfunc(year(&amp;amp;edate.));&lt;/P&gt;&lt;P&gt;/* %let month=%sysfunc(month(&amp;amp;end_dt.)); */&lt;BR /&gt;%put &amp;amp;year0.;&lt;BR /&gt;%put &amp;amp;year1.;&lt;BR /&gt;/* %put &amp;amp;month.; */&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%Get_year(2018-12-31);&lt;/P&gt;&lt;P&gt;output:&lt;/P&gt;&lt;P&gt;"&lt;/P&gt;&lt;DIV class="sasSource"&gt;31DEC2018&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;2890&lt;/DIV&gt;&lt;DIV class="sasError"&gt;ERROR: Argument 1 to function YEAR referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.&lt;/DIV&gt;&lt;DIV class="sasError"&gt;ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC&lt;/DIV&gt;&lt;DIV class="sasError"&gt;or %QSYSFUNC function reference is terminated.&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;SPAN&gt;1967&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 01:14:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-year-from-macro-format-date/m-p/550484#M152841</guid>
      <dc:creator>fsuzhang</dc:creator>
      <dc:date>2019-04-12T01:14:28Z</dc:date>
    </item>
    <item>
      <title>Re: extract year from macro format date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-year-from-macro-format-date/m-p/550485#M152842</link>
      <description>You're making life very difficult.  Why not:&lt;BR /&gt;&lt;BR /&gt;%let year = %substr(&amp;amp;end_dt, 1, 4);</description>
      <pubDate>Fri, 12 Apr 2019 02:10:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-year-from-macro-format-date/m-p/550485#M152842</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-04-12T02:10:53Z</dc:date>
    </item>
    <item>
      <title>Re: extract year from macro format date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-year-from-macro-format-date/m-p/550488#M152844</link>
      <description>&lt;P&gt;Thanks,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know this is simple way, but sometime if the input date is not in that format, it doesn't work.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 02:33:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-year-from-macro-format-date/m-p/550488#M152844</guid>
      <dc:creator>fsuzhang</dc:creator>
      <dc:date>2019-04-12T02:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: extract year from macro format date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-year-from-macro-format-date/m-p/550491#M152846</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;sometime if the input date is not in that format, it doesn't work.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. If it's not in this format then this won't work&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;%let edate=%sysfunc(inputn(&amp;amp;end_dt, yymmdd10.), date9.);&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2. What other strings formats do you expect?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 03:14:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-year-from-macro-format-date/m-p/550491#M152846</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-04-12T03:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: extract year from macro format date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-year-from-macro-format-date/m-p/550492#M152847</link>
      <description>&lt;P&gt;Is this what you want ? Previously your &amp;amp;edate. was not a date&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Get_year(end_dt);

%let edate=%sysfunc(inputn(&amp;amp;end_dt, yymmdd10.));
%let policy_dt = %sysfunc(intnx(month ,&amp;amp;edate., 30,end));

%let year0 =%sysfunc(year(&amp;amp;policy_dt.)); 
%let year1 =%sysfunc(year(&amp;amp;edate.));
%let month=%sysfunc(month(&amp;amp;edate.));
%put &amp;amp;year0.;
%put &amp;amp;year1.;
%put &amp;amp;month.;
%mend;

%Get_year(2018-12-31);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Apr 2019 03:44:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-year-from-macro-format-date/m-p/550492#M152847</guid>
      <dc:creator>34reqrwe</dc:creator>
      <dc:date>2019-04-12T03:44:22Z</dc:date>
    </item>
  </channel>
</rss>

