<?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: How to set up a variable that shows the previous years in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-set-up-a-macro-differences-between-years/m-p/778715#M247911</link>
    <description>&lt;P&gt;You function call is not correct. Whet you will get with YEAR(TODAY()-4 is 2021-4, that is 2017. If you format that as a date, you will get a date that is 2017 days from 01JAN1960.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead, use the INTNX function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date_old=%sysfunc(intnx(year,"&amp;amp;sysdate9."d,-4), yymmd7.)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead of the TODAY function, I used the automatic variable SYSDATE9, which contains the date that the SAS system was started (would normally be today).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you must use the TODAY function, you must enclose that in as %SYSFUNC call as well:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date_old=%sysfunc(intnx(year,%sysfunc(TODAY()),-4), yymmd7.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 05 Nov 2021 12:09:38 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2021-11-05T12:09:38Z</dc:date>
    <item>
      <title>How to set up a macro differences between years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-set-up-a-macro-differences-between-years/m-p/778704#M247905</link>
      <description>&lt;P&gt;I would like to set a variable so that proc format always subtracts 3 years from today (). Date_old should be substract todaty_date - 3 years and given 2019 for example This is my code:&lt;/P&gt;&lt;PRE&gt;%let date_old=%sysfunc(YEAR(Today()-3), yymmd7.);

proc format;
    value date_less low-'date_old' = 'Exp' other=[yymmd7.];
run;&lt;/PRE&gt;&lt;P&gt;But i see error on log :&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;NOTE: Writing HTML5(EGHTML) Body file: EGHTML&lt;BR /&gt;ERROR: Required operator not found in expression: Today()-4&lt;BR /&gt;ERROR: Argument 1 to function YEAR referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.&lt;BR /&gt;ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC&lt;BR /&gt;or %QSYSFUNC function reference is terminated.&lt;BR /&gt;27&lt;/P&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Fri, 05 Nov 2021 12:04:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-set-up-a-macro-differences-between-years/m-p/778704#M247905</guid>
      <dc:creator>Palucci</dc:creator>
      <dc:date>2021-11-05T12:04:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to set up a variable that shows the previous years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-set-up-a-macro-differences-between-years/m-p/778710#M247907</link>
      <description>&lt;P&gt;To compute &amp;amp;date_old, use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date_old=%sysfunc(intnx(year,%sysfunc(Today()),-3));
%put &amp;amp;=date_old;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that %sysfunc has to be called twice, once to make use of the INTNX function and once to make use of the TODAY() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above code produces a result which is the first day of the year, I don't know if that's really what you want, you didn't actually say what day of the year you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your PROC FORMAT, you do not need (and should not use) formatted macro variables (you rarely need formatted macro variables unless the macro variable is to be used in a title, label or file name).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
    value date_less low-&amp;amp;date_old = 'Exp' other=[yymmd7.];
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Nov 2021 12:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-set-up-a-macro-differences-between-years/m-p/778710#M247907</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-05T12:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to set up a variable that shows the previous years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-set-up-a-macro-differences-between-years/m-p/778715#M247911</link>
      <description>&lt;P&gt;You function call is not correct. Whet you will get with YEAR(TODAY()-4 is 2021-4, that is 2017. If you format that as a date, you will get a date that is 2017 days from 01JAN1960.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead, use the INTNX function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date_old=%sysfunc(intnx(year,"&amp;amp;sysdate9."d,-4), yymmd7.)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead of the TODAY function, I used the automatic variable SYSDATE9, which contains the date that the SAS system was started (would normally be today).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you must use the TODAY function, you must enclose that in as %SYSFUNC call as well:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date_old=%sysfunc(intnx(year,%sysfunc(TODAY()),-4), yymmd7.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Nov 2021 12:09:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-set-up-a-macro-differences-between-years/m-p/778715#M247911</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2021-11-05T12:09:38Z</dc:date>
    </item>
  </channel>
</rss>

