<?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: How to round Interval date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-round-Interval-date/m-p/376113#M90228</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello again;&lt;/P&gt;&lt;P&gt;I thought about this way to get what I want.&lt;/P&gt;&lt;PRE&gt;Data one; &lt;BR /&gt; input V U ; &lt;BR /&gt; informat V U date9. duration; &lt;BR /&gt; format V U date9.; &lt;BR /&gt; infile datalines missover; &lt;BR /&gt;datalines; &lt;BR /&gt;15feb2012 1jan2012 &lt;BR /&gt;15feb2012 14jan2012&lt;BR /&gt;15feb2012 15jan2012&lt;BR /&gt;15apr2012 15jan2012&lt;BR /&gt;; &lt;BR /&gt;run;&lt;BR /&gt;data one;&lt;BR /&gt;set one;&lt;BR /&gt;&lt;BR /&gt;month_diff=intck('month',U,V,'C');&lt;BR /&gt;b=intnx('month',U,month_diff,'sameday');&lt;BR /&gt;days_diff=intck('day',U,b,'C');&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if c&amp;gt;0 then month_duration =month_diff+1;&lt;BR /&gt;else month_duration=month_diff;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 14 Jul 2017 17:20:40 GMT</pubDate>
    <dc:creator>adil256</dc:creator>
    <dc:date>2017-07-14T17:20:40Z</dc:date>
    <item>
      <title>How to round Interval date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-round-Interval-date/m-p/375710#M90108</link>
      <description>&lt;P&gt;Hi everone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got an issue when it comes to computed date interval in month.&lt;/P&gt;&lt;P&gt;I would like to round up the month when 1 day&amp;nbsp; or more have elapsed during the month&amp;nbsp;(ex: 3months and 1 day should be considered as 4months; 2 months and 5 days = 3 months;&amp;nbsp; 11 months and 0 days&amp;nbsp;should be 11 months).&lt;/P&gt;&lt;P&gt;I'm using this function but it only round up when the half of the month elapsed.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;SPAN&gt;&lt;STRONG&gt;Data&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;one;&lt;BR /&gt;&lt;/SPAN&gt; &lt;SPAN&gt;input&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;V&amp;nbsp;U;&lt;BR /&gt;&lt;/SPAN&gt; &lt;SPAN&gt;informat&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;V&amp;nbsp;U&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;date9.&lt;/SPAN&gt;; &lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;format&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;V&amp;nbsp;U&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;date9.&lt;/SPAN&gt;; &lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;infile&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN&gt;datalines&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN&gt;missover&lt;/SPAN&gt;; &lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;datalines&lt;/SPAN&gt;; &lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;15feb2012&amp;nbsp;1jan2012&lt;BR /&gt;15feb2012&amp;nbsp;14jan2012&lt;BR /&gt;15feb2012&amp;nbsp;15jan2012&lt;BR /&gt;15apr2012&amp;nbsp;15jan2012&lt;BR /&gt;&lt;/SPAN&gt;; &lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN&gt;run&lt;/SPAN&gt;&lt;/STRONG&gt;; &lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN&gt;data&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;one;&lt;BR /&gt;&lt;/SPAN&gt; &lt;SPAN&gt;set&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;one;&lt;BR /&gt;&lt;/SPAN&gt; &lt;SPAN&gt;duration&amp;nbsp;=&amp;nbsp;max(int((V-U)/(&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN&gt;365.25&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;/&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN&gt;12&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;)+&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN&gt;0.5&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;),&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;);&lt;BR /&gt;&lt;/SPAN&gt; &lt;STRONG&gt;&lt;SPAN&gt;run&lt;/SPAN&gt;&lt;/STRONG&gt;; &lt;SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN&gt;Data&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;want;&lt;BR /&gt;&lt;/SPAN&gt; &lt;SPAN&gt;input&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;V&amp;nbsp;U&amp;nbsp;duration;&lt;BR /&gt;&lt;/SPAN&gt; &lt;SPAN&gt;informat&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;V&amp;nbsp;U&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;date9.&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;duration;&lt;BR /&gt;&lt;/SPAN&gt; &lt;SPAN&gt;format&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;V&amp;nbsp;U&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;date9.&lt;/SPAN&gt;; &lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;infile&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN&gt;datalines&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN&gt;missover&lt;/SPAN&gt;; &lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;datalines&lt;/SPAN&gt;; &lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;15feb2012&amp;nbsp;1jan2012&amp;nbsp;2&lt;BR /&gt;15feb2012&amp;nbsp;14jan2012&amp;nbsp;2&lt;BR /&gt;15feb2012&amp;nbsp;15jan2012&amp;nbsp;1&lt;BR /&gt;15apr2012&amp;nbsp;15jan2012&amp;nbsp;3&lt;BR /&gt;&lt;/SPAN&gt;; &lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN&gt;run&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Any help would be grateful. Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2017 14:44:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-round-Interval-date/m-p/375710#M90108</guid>
      <dc:creator>adil256</dc:creator>
      <dc:date>2017-07-13T14:44:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to round Interval date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-round-Interval-date/m-p/375727#M90115</link>
      <description>&lt;P&gt;Sorry, that doesn't make sense, and the code you provided doesn't work. &amp;nbsp;What is the duration variable for? &amp;nbsp;If you just want to round up month then use intck('month',date,1) on a date variable to move it one month forward, dates cannot have 00, so any date you have will automatically be 1 day into the month. &amp;nbsp;If you don't have day, then cats('01',your_date) then increment that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code formatted for others to use:&lt;/P&gt;
&lt;PRE&gt;Data one; 
  input V U; 
  informat V U date9.; 
  format V U date9.;
  infile datalines missover; 
datalines; 
15feb2012 1jan201215
feb2012 14jan201215
feb2012 15jan201215
apr2012 15jan2012
; 
run; 

data one; 
  set one; 
  duration = max(int((V-U)/(365.25/12)+0.5),1); 
run; 

Data want; 
  input V U duration; 
  informat V U date9. duration; 
  format V U date9.; 
  infile datalines missover; 
datalines; 
15feb2012 1jan2012 2
15feb2012 14jan2012 2
15feb2012 15jan2012 1
15apr2012 15jan2012 3
; 
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Jul 2017 15:03:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-round-Interval-date/m-p/375727#M90115</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-07-13T15:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to round Interval date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-round-Interval-date/m-p/375730#M90117</link>
      <description>&lt;P&gt;If you are happy otherwise with your formula, switch from the MAX function to the CEIL function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;Adding to an incomplete answer here ...&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;CEIL would have to replace both MAX and INT (not just replace MAX ... INT gets removed).&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;Be wary of using INTCK unless you understand what it does.&amp;nbsp; Some examples:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;30Jan2017 to 02Feb2017&amp;nbsp; is 1 month&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;02Jan2017 to 31Jan2017 is 0 months&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;Additional considerations:&amp;nbsp; How many months are in this interval?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;28Jan2017 to 28Feb2017&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2017 16:15:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-round-Interval-date/m-p/375730#M90117</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-13T16:15:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to round Interval date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-round-Interval-date/m-p/375731#M90118</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/43088"&gt;@adil256&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi everone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to round up the month when 1 day&amp;nbsp; or more have elapsed during the month&amp;nbsp;(ex: 3months and 1 day should be considered as 4months; 2 months and 5 days = 3 months;&amp;nbsp; 11 months and 0 days&amp;nbsp;should be 11 months).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This if flawed logic. Look at your third record. You have days in both months, February and January but you show that you want 1 month duration. You also are using the average number of days in a month but are trying to use 'months' as a fixed term when it doesn't have one. To solve this problem you need to clarify your logic first.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are a bunch of different ways you could calculate this. Note that I used&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;suggestion of moving the date to the beginning/end of the boundarys.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data two;
	set one;
	diff_days = v-u;
	diff_avg_months = (v-u)/(365.25/12);
	diff_months = ceil(diff_avg_months);
	durationC=intck('month', intnx('month', u, 0, 'b'), intnx('month', v, 0, 'e'), 'C');
	durationD=intck('month', intnx('month', u, 0, 'b'), intnx('month', v, 0, 'e'), 'D');

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2017 15:18:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-round-Interval-date/m-p/375731#M90118</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-13T15:18:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to round Interval date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-round-Interval-date/m-p/375734#M90119</link>
      <description>&lt;P&gt;Here is another way:&lt;/P&gt;
&lt;PRE&gt;data want;
  set one;
  if day(U) lt day(V) then duration=intck('month',U,V)+1;
  else duration=intck('month',U,V);
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2017 15:22:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-round-Interval-date/m-p/375734#M90119</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-13T15:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to round Interval date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-round-Interval-date/m-p/375743#M90121</link>
      <description>&lt;P&gt;may excuse me if I expressed myself poorly. The duration variable stands for the number of months elapsed between two dates. the function intck gives me the number of months really elapsed betwen the dates. for example, If 3 months and 17 days have been&amp;nbsp;elapsed the intck function will give 3 months elapsed. What I'm looking for it's to considerer these 3 months and 17 days as 4 months elapsed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;thank you but ceil function doesn't work perfectly as well :s; the number of month between 15jan2012 and 15feb2012.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will think about your way of doing it. Thank u very much. &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;&amp;nbsp;,&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp; and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2017 15:47:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-round-Interval-date/m-p/375743#M90121</guid>
      <dc:creator>adil256</dc:creator>
      <dc:date>2017-07-13T15:47:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to round Interval date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-round-Interval-date/m-p/375772#M90134</link>
      <description>&lt;P&gt;That's because a 'month' doesn't have a standard definition. 15Jan to 15th of Feb is 31 days which is more than an average month. Technically thats 1 month + less than one day, so in this case you're rounding down when in the others you're rounding up.&amp;nbsp;&lt;/P&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2017 17:35:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-round-Interval-date/m-p/375772#M90134</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-13T17:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to round Interval date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-round-Interval-date/m-p/376113#M90228</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello again;&lt;/P&gt;&lt;P&gt;I thought about this way to get what I want.&lt;/P&gt;&lt;PRE&gt;Data one; &lt;BR /&gt; input V U ; &lt;BR /&gt; informat V U date9. duration; &lt;BR /&gt; format V U date9.; &lt;BR /&gt; infile datalines missover; &lt;BR /&gt;datalines; &lt;BR /&gt;15feb2012 1jan2012 &lt;BR /&gt;15feb2012 14jan2012&lt;BR /&gt;15feb2012 15jan2012&lt;BR /&gt;15apr2012 15jan2012&lt;BR /&gt;; &lt;BR /&gt;run;&lt;BR /&gt;data one;&lt;BR /&gt;set one;&lt;BR /&gt;&lt;BR /&gt;month_diff=intck('month',U,V,'C');&lt;BR /&gt;b=intnx('month',U,month_diff,'sameday');&lt;BR /&gt;days_diff=intck('day',U,b,'C');&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if c&amp;gt;0 then month_duration =month_diff+1;&lt;BR /&gt;else month_duration=month_diff;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 17:20:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-round-Interval-date/m-p/376113#M90228</guid>
      <dc:creator>adil256</dc:creator>
      <dc:date>2017-07-14T17:20:40Z</dc:date>
    </item>
  </channel>
</rss>

