<?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: counting months in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/counting-months/m-p/111199#M23041</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are all of your data pairs &lt;STRONG&gt;always&lt;/STRONG&gt; within the same calendar year? Are the dates SAS date values or strings?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For your example this seems to work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;informat start_date end_date mmddyy10.;&lt;/P&gt;&lt;P&gt;format start_date end_date mmddyy10.;&lt;/P&gt;&lt;P&gt;input start_date end_date;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;01/01/2010 12/31/2010&lt;/P&gt;&lt;P&gt;05/01/2010 12/31/2010&lt;/P&gt;&lt;P&gt;05/01/2010 05/14/2010&lt;/P&gt;&lt;P&gt;06/13/2010 08/28/2010&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;array months month1-month12;&lt;/P&gt;&lt;P&gt;do i= month(start_date) to month(end_date);&lt;/P&gt;&lt;P&gt;months&lt;I&gt;=1;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;drop i;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 17 Apr 2013 17:39:28 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2013-04-17T17:39:28Z</dc:date>
    <item>
      <title>counting months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/counting-months/m-p/111198#M23040</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a range of dates.&amp;nbsp; I would like to count how many months are within each set of dates along with creating a new variable for each month. For example;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input start_date end_date;&lt;/P&gt;&lt;P&gt;01/01/2010 12/31/2010&lt;/P&gt;&lt;P&gt;05/01/2010 12/31/2010&lt;/P&gt;&lt;P&gt;05/01/2010 05/14/2010&lt;/P&gt;&lt;P&gt;06/13/2010 08/28/2010;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to create a new variable for each month that contains the counts for each number of months between the start and end dates. For example;&lt;/P&gt;&lt;P&gt;01/01/2010 12/31/2010 --&amp;gt; month1=1 month2=1, month3=1 . . . .month12=1;&lt;/P&gt;&lt;P&gt;05/01/2010 12/31/2010 --&amp;gt; month5=1 month6=1, month7=1 . . . .month12=1;&lt;/P&gt;&lt;P&gt;05/01/2010 05/14/2010 --&amp;gt; month5=1;&lt;/P&gt;&lt;P&gt;06/13/2010 08/28/2010 --&amp;gt; month6=1 month7=1 month8=1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Based on this sample data, in the end I should have the below counts for each month.&lt;/P&gt;&lt;P&gt;Month1=1&lt;/P&gt;&lt;P&gt;Month2=1&lt;/P&gt;&lt;P&gt;Month3=1&lt;/P&gt;&lt;P&gt;Month4=1&lt;/P&gt;&lt;P&gt;Month5=3&lt;/P&gt;&lt;P&gt;Month6=3&lt;/P&gt;&lt;P&gt;Month7=3&lt;/P&gt;&lt;P&gt;Month8=3&lt;/P&gt;&lt;P&gt;Month9=2&lt;/P&gt;&lt;P&gt;Month10=2&lt;/P&gt;&lt;P&gt;Month11=2&lt;/P&gt;&lt;P&gt;Month12=2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;Sophia&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Apr 2013 17:27:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/counting-months/m-p/111198#M23040</guid>
      <dc:creator>sophia_SAS</dc:creator>
      <dc:date>2013-04-17T17:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: counting months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/counting-months/m-p/111199#M23041</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are all of your data pairs &lt;STRONG&gt;always&lt;/STRONG&gt; within the same calendar year? Are the dates SAS date values or strings?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For your example this seems to work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;informat start_date end_date mmddyy10.;&lt;/P&gt;&lt;P&gt;format start_date end_date mmddyy10.;&lt;/P&gt;&lt;P&gt;input start_date end_date;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;01/01/2010 12/31/2010&lt;/P&gt;&lt;P&gt;05/01/2010 12/31/2010&lt;/P&gt;&lt;P&gt;05/01/2010 05/14/2010&lt;/P&gt;&lt;P&gt;06/13/2010 08/28/2010&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;array months month1-month12;&lt;/P&gt;&lt;P&gt;do i= month(start_date) to month(end_date);&lt;/P&gt;&lt;P&gt;months&lt;I&gt;=1;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;drop i;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Apr 2013 17:39:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/counting-months/m-p/111199#M23041</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-04-17T17:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: counting months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/counting-months/m-p/111200#M23042</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks!&amp;nbsp; That worked perfectly.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Apr 2013 17:59:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/counting-months/m-p/111200#M23042</guid>
      <dc:creator>sophia_SAS</dc:creator>
      <dc:date>2013-04-17T17:59:00Z</dc:date>
    </item>
  </channel>
</rss>

