<?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 to derive current year in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-derive-current-year/m-p/509783#M137095</link>
    <description>&lt;P&gt;Data step functions need %sysfunc to be evaluated in macro expressions.&lt;/P&gt;</description>
    <pubDate>Fri, 02 Nov 2018 08:32:54 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-11-02T08:32:54Z</dc:date>
    <item>
      <title>Macro to derive current year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-derive-current-year/m-p/509781#M137094</link>
      <description>&lt;P&gt;If I execute the following code, I could see the result as '2018'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
yr=put(year(date()),4.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However If I trying to turn it into macro as below, it is not producing the desired result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let yr=put(year(date()),4.);
%put &amp;amp;yr;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I need the macro to derive current year so that I can call that macro to derive the file name and data set name .&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 08:20:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-derive-current-year/m-p/509781#M137094</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-11-02T08:20:37Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to derive current year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-derive-current-year/m-p/509783#M137095</link>
      <description>&lt;P&gt;Data step functions need %sysfunc to be evaluated in macro expressions.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 08:32:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-derive-current-year/m-p/509783#M137095</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-11-02T08:32:54Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to derive current year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-derive-current-year/m-p/509788#M137099</link>
      <description>&lt;P&gt;And why do you need to waste resource putting something already known into a macro variable?&lt;/P&gt;
&lt;PRE&gt;data _null_;
  file "want_%sysfunc(year(date(),4.).txt";
...&lt;/PRE&gt;
&lt;PRE&gt;data want_%sysfunc(year(date(),4.);
...&lt;/PRE&gt;
&lt;P&gt;I would also suggest that putting data - in this case year - into names is really not a good idea, nor is splitting up same data.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 08:50:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-derive-current-year/m-p/509788#M137099</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-02T08:50:56Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to derive current year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-derive-current-year/m-p/509794#M137102</link>
      <description>&lt;P&gt;I'm receiving the following error after executing the code below. Am I missing something?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let curr_year=%sysfunc(year(date()));
%put &amp;amp;curr_year.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
ERROR: Required operator not found in expression: date() 
ERROR: Argument 1 to function YEAR referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list.  Execution of %SYSCALL statement or %SYSFUNC 
       or %QSYSFUNC function reference is terminated.
24         %let curr_year=%sysfunc(year(date()));
25         %put &amp;amp;curr_year.;
.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 09:27:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-derive-current-year/m-p/509794#M137102</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-11-02T09:27:17Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to derive current year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-derive-current-year/m-p/509798#M137103</link>
      <description>&lt;P&gt;&lt;EM&gt;Two&lt;/EM&gt; data step functions, &lt;EM&gt;two&lt;/EM&gt; sysfunc's:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let curr_year=%sysfunc(year(%sysfunc(date())));
%put &amp;amp;curr_year.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You need to develop a little more creatitvity and audacity in playing around with code along logical lines of thinking. Also see Maxim 4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 09:48:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-derive-current-year/m-p/509798#M137103</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-11-02T09:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to derive current year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-derive-current-year/m-p/509822#M137112</link>
      <description>&lt;P&gt;You can just do it with a single function call, as %sysfunc accepts a format (in this case year4.):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let yr=%sysfunc(date(),year4.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Nov 2018 11:14:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-derive-current-year/m-p/509822#M137112</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-11-02T11:14:51Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to derive current year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-derive-current-year/m-p/509834#M137116</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;If I execute the following code, I could see the result as '2018'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
yr=put(year(date()),4.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However If I trying to turn it into macro as below, it is not producing the desired result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;First, you are trying to turn this into a MACRO VARIABLE, not a MACRO. A macro and a macro variable are not the same thing, so please don't use these two terms interchangeably. But, since you already have your data step code working, then you can create a macro variable right there in the data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
yr=put(year(date()),4.);
call symputx('yr',yr);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But&amp;nbsp;it is completely unnecessary to format this inside a PUT statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call symputx('yr',year(date()));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 12:34:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-derive-current-year/m-p/509834#M137116</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-11-02T12:34:53Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to derive current year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-derive-current-year/m-p/509880#M137129</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I'm receiving the following error after executing the code below. Am I missing something?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let curr_year=%sysfunc(year(date()));
%put &amp;amp;curr_year.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
ERROR: Required operator not found in expression: date() 
ERROR: Argument 1 to function YEAR referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list.  Execution of %SYSCALL statement or %SYSFUNC 
       or %QSYSFUNC function reference is terminated.
24         %let curr_year=%sysfunc(year(date()));
25         %put &amp;amp;curr_year.;
.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;EVERY instance of a data step function requires the use of the %sysfunc function when working in the macro language. Which is why you will find a largish number of folks do complex manipulations in a data step and then create a macro variable if needed. If you search this forum on macro and date you will find some lines of code showing 5 and more %sysfunc() calls. Between nesting complexities, a large number of parentheses and just plain long lines of code these can get hard to read and modify.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 14:24:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-derive-current-year/m-p/509880#M137129</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-11-02T14:24:27Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to derive current year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-derive-current-year/m-p/509889#M137135</link>
      <description>&lt;P&gt;Do you want a macro?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro year;
%sysfunc(date(),year4)
%mend year;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or just a macro variable (or symbol)?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let yr=%sysfunc(date(),year4);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do you need the current year?&amp;nbsp; Or just the year that the SAS session started running?&amp;nbsp; Are you planning to run this on New Year's eve?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let yr=%substr(&amp;amp;sysdate9,6);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 14:51:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-derive-current-year/m-p/509889#M137135</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-02T14:51:06Z</dc:date>
    </item>
  </channel>
</rss>

