<?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: Calculate months between two dates in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculate-months-between-two-dates-in-SAS/m-p/881576#M348335</link>
    <description>Remove the format (YYMMDD) from the macro variables.</description>
    <pubDate>Tue, 20 Jun 2023 19:05:23 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2023-06-20T19:05:23Z</dc:date>
    <item>
      <title>Calculate months between two dates in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-months-between-two-dates-in-SAS/m-p/881570#M348334</link>
      <description>Hi all,&lt;BR /&gt;somehow I can't calculate the months between 20211231 and 20230228.&lt;BR /&gt;&lt;BR /&gt;Code:Copy to clipboard&lt;BR /&gt;%let End = %sysfunc(intnx(month,%sysfunc(today()),-4,e),YYMMDDN8.);&lt;BR /&gt;%let Begin = %sysfunc(intnx(year, %sysfunc(date()), -2, e),YYMMDDN8.);&lt;BR /&gt;%put &amp;amp;Begin;&lt;BR /&gt;%put &amp;amp;End;&lt;BR /&gt;&lt;BR /&gt;%let count_months =%sysfunc(intck(month,&amp;amp;Begin.,&amp;amp;End.));&lt;BR /&gt;%put &amp;amp;count_months;&lt;BR /&gt;&lt;BR /&gt;I get the following log statement:&lt;BR /&gt;WARNING: An argument to the function INTCK referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.&lt;BR /&gt;NOTE: Mathematical operations could not be performed during %SYSFUNC function execution.&lt;BR /&gt;The result of the operations have been set to a missing value.&lt;BR /&gt;&lt;BR /&gt;Can someone help me with synthax?&lt;BR /&gt;&lt;BR /&gt;Many thanks in advance.&lt;BR /&gt;&lt;BR /&gt;Kind regards,&lt;BR /&gt;Ben</description>
      <pubDate>Tue, 20 Jun 2023 18:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-months-between-two-dates-in-SAS/m-p/881570#M348334</guid>
      <dc:creator>BenEntrew</dc:creator>
      <dc:date>2023-06-20T18:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate months between two dates in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-months-between-two-dates-in-SAS/m-p/881576#M348335</link>
      <description>Remove the format (YYMMDD) from the macro variables.</description>
      <pubDate>Tue, 20 Jun 2023 19:05:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-months-between-two-dates-in-SAS/m-p/881576#M348335</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-06-20T19:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate months between two dates in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-months-between-two-dates-in-SAS/m-p/881577#M348336</link>
      <description>&lt;P&gt;A SAS date value is an integer&amp;nbsp;&lt;EM&gt;count of days, starting at 1960-01-01&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;So the number 20211231 would be&amp;nbsp;&lt;EM&gt;very far&lt;/EM&gt; in the future, beyond the range of available formats.&lt;/P&gt;
&lt;P&gt;Maxim 28: Macro Variables Need no Formats.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let End = %sysfunc(intnx(month,%sysfunc(today()),-4,e));
%let Begin = %sysfunc(intnx(year,%sysfunc(today()),-2,e));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Jun 2023 19:05:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-months-between-two-dates-in-SAS/m-p/881577#M348336</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-06-20T19:05:47Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate months between two dates in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-months-between-two-dates-in-SAS/m-p/881579#M348337</link>
      <description>&lt;P&gt;DO NOT format macro variables. This prevents mathematical operations from working correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use unformatted macro variables&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let End = %sysfunc(intnx(month,%sysfunc(today()),-4,e));
%let Begin = %sysfunc(intnx(year, %sysfunc(date()), -2, e));
%put &amp;amp;Begin;
%put &amp;amp;End;

%let count_months =%sysfunc(intck(month,&amp;amp;Begin.,&amp;amp;End.));
%put &amp;amp;count_months;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Jun 2023 19:06:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-months-between-two-dates-in-SAS/m-p/881579#M348337</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-20T19:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate months between two dates in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-months-between-two-dates-in-SAS/m-p/881580#M348338</link>
      <description>&lt;P&gt;Don't apply the format when creating the value, that changes the values that INTCK expects to see.&lt;/P&gt;
&lt;P&gt;When you formatted the value you changed a numeric value on the order of 23181 to 20230620. INTCK and other date functions in SAS expect to see a value that is the number of days since 01JAN1960 as an argument. So the formatted value such as 20230620 would be roughly in year 55,388. The SAS date functions won't work with any dates past the year 20,000 .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a need for a formatted&amp;nbsp; version of Begin and End then create separate non-formatted variables.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2023 19:06:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-months-between-two-dates-in-SAS/m-p/881580#M348338</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-06-20T19:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate months between two dates in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-months-between-two-dates-in-SAS/m-p/881662#M348367</link>
      <description>Thanks for your help.&lt;BR /&gt;Now it works.&lt;BR /&gt;&lt;BR /&gt;Kind regards,&lt;BR /&gt;Ben</description>
      <pubDate>Wed, 21 Jun 2023 09:00:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-months-between-two-dates-in-SAS/m-p/881662#M348367</guid>
      <dc:creator>BenEntrew</dc:creator>
      <dc:date>2023-06-21T09:00:28Z</dc:date>
    </item>
  </channel>
</rss>

