<?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: Set Macro Variable to Date Two Years in Past in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Set-Macro-Variable-to-Date-Two-Years-in-Past/m-p/576595#M163229</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;sysdate9;
%put %sysfunc(date());
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Look at the results of these two commands.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;INTNX and similar calendar functions requires SAS dates, which are integers, not formatted (and human readable) dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So &amp;amp;sysdate9 (which produces formatted human readable dates) will not work in INTNX. You need %sysfunc(date()) (which produces a valid SAS date, an integer) in INTNX.&lt;/P&gt;</description>
    <pubDate>Thu, 25 Jul 2019 14:00:03 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-07-25T14:00:03Z</dc:date>
    <item>
      <title>Set Macro Variable to Date Two Years in Past</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-Macro-Variable-to-Date-Two-Years-in-Past/m-p/576594#M163228</link>
      <description>&lt;P&gt;I am attempting to set a macro variable to a date two years in the past. I have tried the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let lookback = intnx('year',&amp;amp;sysdate9,-2,same);
%put &amp;amp;lookback;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Which then gives me the following in the log:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;26         %let lookback = intnx('year',&amp;amp;sysdate9,-2,same);
27         %put &amp;amp;lookback;
intnx('year',25JUL2019,-2,same)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So it doesn't seem to be resolving my variable correctly, but I can't figure out why.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2019 13:54:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-Macro-Variable-to-Date-Two-Years-in-Past/m-p/576594#M163228</guid>
      <dc:creator>A_SAS_Man</dc:creator>
      <dc:date>2019-07-25T13:54:41Z</dc:date>
    </item>
    <item>
      <title>Re: Set Macro Variable to Date Two Years in Past</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-Macro-Variable-to-Date-Two-Years-in-Past/m-p/576595#M163229</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;sysdate9;
%put %sysfunc(date());
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Look at the results of these two commands.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;INTNX and similar calendar functions requires SAS dates, which are integers, not formatted (and human readable) dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So &amp;amp;sysdate9 (which produces formatted human readable dates) will not work in INTNX. You need %sysfunc(date()) (which produces a valid SAS date, an integer) in INTNX.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2019 14:00:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-Macro-Variable-to-Date-Two-Years-in-Past/m-p/576595#M163229</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-07-25T14:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: Set Macro Variable to Date Two Years in Past</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-Macro-Variable-to-Date-Two-Years-in-Past/m-p/576596#M163230</link>
      <description>&lt;P&gt;Just a few minor tweaks.&amp;nbsp; Try it this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let lookback = %sysfunc(intnx(year,%sysevalf("&amp;amp;sysdate9"d),-2,same));
%put &amp;amp;lookback;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jul 2019 14:01:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-Macro-Variable-to-Date-Two-Years-in-Past/m-p/576596#M163230</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-07-25T14:01:30Z</dc:date>
    </item>
    <item>
      <title>Re: Set Macro Variable to Date Two Years in Past</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-Macro-Variable-to-Date-Two-Years-in-Past/m-p/576597#M163231</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let lookback = %sysfunc(intnx(year,"&amp;amp;sysdate9"d,-2,same),date9.);
%put &amp;amp;=lookback;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jul 2019 14:00:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-Macro-Variable-to-Date-Two-Years-in-Past/m-p/576597#M163231</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-07-25T14:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: Set Macro Variable to Date Two Years in Past</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-Macro-Variable-to-Date-Two-Years-in-Past/m-p/576600#M163234</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Just a few minor tweaks.&amp;nbsp; Try it this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let lookback = %sysfunc(intnx(year,%sysevalf("&amp;amp;sysdate9"d),-2,same));
%put &amp;amp;lookback;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Adding to my explanation above, the method from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;works because putting &amp;amp;sysdate9 inside double quotes and then appending the letter d on the end — "&amp;amp;sysdate9"d — turns the human readable date that results from &amp;amp;sysdate9 into an integer which is required by INTNX.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My OPINION is that its easier to work with unformatted dates in INTNX and similar functions, rather than format them and then unformat them to get them to work. Naturally, there is a limitation here, if a human has to enter the date into the code (hard code it), then the human has to use some formatted date and you have to convert it to an integer to work in INTNX; but if you want today's date, that doesn't apply.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2019 14:16:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-Macro-Variable-to-Date-Two-Years-in-Past/m-p/576600#M163234</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-07-25T14:16:45Z</dc:date>
    </item>
  </channel>
</rss>

