<?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: Intnx to subtract year in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Intnx-to-subtract-year/m-p/815643#M321928</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Appreciate if someone of you help me understand why this code producing the CURR_DATE value as 28MAY1961 instead of 28MAY2021?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test;
CASE_FILL_DATE='29MAY2022'd;
format CURR_DATE CASE_FILL_DATE date9.;
CURR_DATE=CASE_FILL_DATE - INTNX('YEAR',TODAY(),-1);
run;
&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You are calculating the date that is the beginning of last year, so the date 01JAN2021.&amp;nbsp; You then subtract that from a date that is 29MAY2022.&amp;nbsp; So the difference is about 1 year and 6 months.&amp;nbsp; Since SAS numbers days from 01JAn1960 it makes sense that the result is some time in the middle on 1961.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to use INTNX() to move back one interval, but not to the beginning of the interval, then make sure to use 'same' as the value for the third argument.&lt;/P&gt;
&lt;PRE&gt;7484  data want;
7485    last_year = intnx('year',today(),-1,'same');
7486    format last_year date9.;
7487    put last_year= ;
7488  run;

last_year=29MAY2021
&lt;/PRE&gt;</description>
    <pubDate>Mon, 30 May 2022 02:59:55 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-05-30T02:59:55Z</dc:date>
    <item>
      <title>Intnx to subtract year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intnx-to-subtract-year/m-p/815642#M321927</link>
      <description>&lt;P&gt;Appreciate if someone of you help me understand why this code producing the CURR_DATE value as 28MAY1961 instead of 28MAY2021?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test;
CASE_FILL_DATE='29MAY2022'd;
format CURR_DATE CASE_FILL_DATE date9.;
CURR_DATE=CASE_FILL_DATE - INTNX('YEAR',TODAY(),-1);
run;
&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 May 2022 02:20:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intnx-to-subtract-year/m-p/815642#M321927</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2022-05-30T02:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: Intnx to subtract year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intnx-to-subtract-year/m-p/815643#M321928</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Appreciate if someone of you help me understand why this code producing the CURR_DATE value as 28MAY1961 instead of 28MAY2021?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test;
CASE_FILL_DATE='29MAY2022'd;
format CURR_DATE CASE_FILL_DATE date9.;
CURR_DATE=CASE_FILL_DATE - INTNX('YEAR',TODAY(),-1);
run;
&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You are calculating the date that is the beginning of last year, so the date 01JAN2021.&amp;nbsp; You then subtract that from a date that is 29MAY2022.&amp;nbsp; So the difference is about 1 year and 6 months.&amp;nbsp; Since SAS numbers days from 01JAn1960 it makes sense that the result is some time in the middle on 1961.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to use INTNX() to move back one interval, but not to the beginning of the interval, then make sure to use 'same' as the value for the third argument.&lt;/P&gt;
&lt;PRE&gt;7484  data want;
7485    last_year = intnx('year',today(),-1,'same');
7486    format last_year date9.;
7487    put last_year= ;
7488  run;

last_year=29MAY2021
&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 May 2022 02:59:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intnx-to-subtract-year/m-p/815643#M321928</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-30T02:59:55Z</dc:date>
    </item>
    <item>
      <title>Re: Intnx to subtract year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intnx-to-subtract-year/m-p/815644#M321929</link>
      <description>&lt;P&gt;If you want to move CASE_FILL_DATE back a year put it in INTNX and use the 'SAME' option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
CASE_FILL_DATE='29MAY2022'd;
format CURR_DATE CASE_FILL_DATE Back_one_year date9.;
CURR_DATE=CASE_FILL_DATE - INTNX('YEAR',TODAY(),-1);
Back_one_year=INTNX('YEAR',CASE_FILL_DATE,-1,'SAME');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 May 2022 03:08:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intnx-to-subtract-year/m-p/815644#M321929</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-05-30T03:08:54Z</dc:date>
    </item>
    <item>
      <title>Re: Intnx to subtract year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intnx-to-subtract-year/m-p/815666#M321938</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Appreciate if someone of you help me understand why this code producing the CURR_DATE value as 28MAY1961 instead of 28MAY2021?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test;
CASE_FILL_DATE='29MAY2022'd;
format CURR_DATE CASE_FILL_DATE date9.;
CURR_DATE=CASE_FILL_DATE - INTNX('YEAR',TODAY(),-1);
run;
&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You can do some easy debugging ... as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
CASE_FILL_DATE='29MAY2022'd;
z=INTNX('YEAR',TODAY(),-1);
CURR_DATE=CASE_FILL_DATE - z;
format z CURR_DATE CASE_FILL_DATE date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you look at the value of Z, you see 01JAN2021, so you are subtracting 28MAY2022 – 01JAN2021 which is a little less than 1.5 years. That doesn't seem to be what you want.&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want an answer of 28MAY2021, there's no subtraction needed, use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;CURR_DATE = INTNX('YEAR',TODAY(),-1,'s');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In essence, the INTNX does the subtraction for you. If your code also does the subtraction, you are doing the subtraction twice, and that is not what you want.&lt;/P&gt;</description>
      <pubDate>Mon, 30 May 2022 10:27:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intnx-to-subtract-year/m-p/815666#M321938</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-30T10:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: Intnx to subtract year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intnx-to-subtract-year/m-p/815697#M321952</link>
      <description>&lt;P&gt;you may find this paper useful:&amp;nbsp;&lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/sugi31/027-31.pd" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings/proceedings/sugi31/027-31.pd&lt;/A&gt;f&lt;/P&gt;</description>
      <pubDate>Mon, 30 May 2022 14:14:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intnx-to-subtract-year/m-p/815697#M321952</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2022-05-30T14:14:49Z</dc:date>
    </item>
  </channel>
</rss>

