<?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: I want to find the number of months between two dates. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-find-the-number-of-months-between-two-dates/m-p/687778#M208839</link>
    <description>&lt;P&gt;First, you don't need macro variables to do this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
NumberOfMonths = INTCK('MONTH', '30Jun2014'd, intnx('month',today(),0,'e'), 'D');
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, if you are going to create macro variables, DO NOT format them. (&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 28&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	call symputx('month_end',intnx('month',today(),0)-1);
	call symputx('start_date','30Jun2014'd);
RUN;

data a;
NumberOfMonths = INTCK('MONTH', &amp;amp;start_date, &amp;amp;month_end, 'D');
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But as I said, in this simple example, macro variables are not needed, nevertheless the advice to NOT format macro variables is a general rule you should follow, with the exception of when the macro variables are going to be used in titles or labels.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Lastly, this part of your code&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;intnx('month',today(),0)-1&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;calculates the day one day previous to today (but yet you call in MONTH_END), is that what you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 14:03:58 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-09-30T14:03:58Z</dc:date>
    <item>
      <title>I want to find the number of months between two dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-find-the-number-of-months-between-two-dates/m-p/687774#M208837</link>
      <description>&lt;P&gt;I want to be able to find the number of months between 2 dates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first date will always be 30 June 2014. My end date will always be the last day of the previous month. I want to then be able to use that number in other parts of code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I.E. Between 30th June 2014 and 31st August 2020 there are 74 months. I want to then be able to call on that 74 in a later For loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried something like this from using another code but I can't get it to work.&lt;/P&gt;&lt;PRE&gt;data _null_;
	call symput('month_end', put(intnx('month',today(),0)-1,date9.));
	call symput('start_date', put(intnx('month','30Jun14'd,0),date9.));
RUN;

%put &amp;amp;month_end.;
%put &amp;amp;Start_date.;

data a;
NumberOfMonths = INTCK('MONTH', '30Jun14'd, &amp;amp;month_end., 'D');
RUN;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Sep 2020 11:28:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-want-to-find-the-number-of-months-between-two-dates/m-p/687774#M208837</guid>
      <dc:creator>RikeshPunja</dc:creator>
      <dc:date>2020-09-30T11:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: I want to find the number of months between two dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-find-the-number-of-months-between-two-dates/m-p/687778#M208839</link>
      <description>&lt;P&gt;First, you don't need macro variables to do this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
NumberOfMonths = INTCK('MONTH', '30Jun2014'd, intnx('month',today(),0,'e'), 'D');
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, if you are going to create macro variables, DO NOT format them. (&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 28&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	call symputx('month_end',intnx('month',today(),0)-1);
	call symputx('start_date','30Jun2014'd);
RUN;

data a;
NumberOfMonths = INTCK('MONTH', &amp;amp;start_date, &amp;amp;month_end, 'D');
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But as I said, in this simple example, macro variables are not needed, nevertheless the advice to NOT format macro variables is a general rule you should follow, with the exception of when the macro variables are going to be used in titles or labels.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Lastly, this part of your code&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;intnx('month',today(),0)-1&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;calculates the day one day previous to today (but yet you call in MONTH_END), is that what you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 14:03:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-want-to-find-the-number-of-months-between-two-dates/m-p/687778#M208839</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-30T14:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: I want to find the number of months between two dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-find-the-number-of-months-between-two-dates/m-p/687820#M208856</link>
      <description>&lt;P&gt;Thank you so much for this.&lt;/P&gt;&lt;P&gt;I've been put on a project in SAS which is quite intermediate but I am a novice but learning as I'm going along.&amp;nbsp;&lt;/P&gt;&lt;P&gt;There was some older code written by someone before me that included macro variables so thought I would adapt that.&lt;/P&gt;&lt;P&gt;Also, I didn't mean to calculate 1 day before today, that was my error. I was trying to get the last day of the previous month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a follow-up question, if I use NumberOfMonths, in a For loop, will it work?&lt;/P&gt;&lt;P&gt;What I am actually trying to get is a list, which has the last day of every month from 30th June 2014 to the last day of the previous month.&lt;/P&gt;&lt;P&gt;Could you help me with that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 14:26:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-want-to-find-the-number-of-months-between-two-dates/m-p/687820#M208856</guid>
      <dc:creator>RikeshPunja</dc:creator>
      <dc:date>2020-09-30T14:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: I want to find the number of months between two dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-find-the-number-of-months-between-two-dates/m-p/687827#M208859</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;What I am actually trying to get is a list, which has the last day of every month from 30th June 2014 to the last day of the previous month.&amp;nbsp;Could you help me with that?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	date='30jun2014'd;
	enddate=today();
	do while (date&amp;lt;enddate);
	    output;
		date=intnx('month',date,1,'e');
	end;
	keep date;
	format date yymmdd10.;
run;
		&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;</description>
      <pubDate>Wed, 30 Sep 2020 15:06:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-want-to-find-the-number-of-months-between-two-dates/m-p/687827#M208859</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-30T15:06:41Z</dc:date>
    </item>
    <item>
      <title>Re: I want to find the number of months between two dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-find-the-number-of-months-between-two-dates/m-p/687847#M208865</link>
      <description>Thank you for this.&lt;BR /&gt;&lt;BR /&gt;I'll try to understand how it works.</description>
      <pubDate>Wed, 30 Sep 2020 15:04:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-want-to-find-the-number-of-months-between-two-dates/m-p/687847#M208865</guid>
      <dc:creator>RikeshPunja</dc:creator>
      <dc:date>2020-09-30T15:04:40Z</dc:date>
    </item>
  </channel>
</rss>

