<?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 Rounding issue in datastep in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rounding-issue-in-datastep/m-p/451299#M113740</link>
    <description>&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; stop_date &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ln_no $ stop_date &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1123 16jun2014&lt;/P&gt;
&lt;P&gt;1124 28dec2017&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; have2;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;months = intck('Month',stop_date,"4apr2018"d);&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Output &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; months&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;1123&amp;nbsp;&amp;nbsp; 6jun2014&amp;nbsp;&amp;nbsp;&amp;nbsp; 46&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;1124&amp;nbsp;&amp;nbsp; 28dec2017&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;I received code that asks for a rounding of the above numbers&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;round(months_between(&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;"&amp;amp;today."d&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;, stop_date),&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;I have not heard of a months_between function so I used the intck function.&amp;nbsp; The code received yields these results&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Output &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; months&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;1123&amp;nbsp;&amp;nbsp; 6jun2014&amp;nbsp;&amp;nbsp;&amp;nbsp; 45.61&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;1124&amp;nbsp;&amp;nbsp; 28dec2017&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3.23&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;It appears the above code rounds down and sends two decimal places.&amp;nbsp; I am attempting to determine how to replicate these exact numbers.&amp;nbsp; The analyst that prepared this code is no longer available&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Apr 2018 19:57:13 GMT</pubDate>
    <dc:creator>Q1983</dc:creator>
    <dc:date>2018-04-04T19:57:13Z</dc:date>
    <item>
      <title>Rounding issue in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rounding-issue-in-datastep/m-p/451299#M113740</link>
      <description>&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; stop_date &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ln_no $ stop_date &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1123 16jun2014&lt;/P&gt;
&lt;P&gt;1124 28dec2017&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; have2;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;months = intck('Month',stop_date,"4apr2018"d);&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Output &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; months&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;1123&amp;nbsp;&amp;nbsp; 6jun2014&amp;nbsp;&amp;nbsp;&amp;nbsp; 46&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;1124&amp;nbsp;&amp;nbsp; 28dec2017&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;I received code that asks for a rounding of the above numbers&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;round(months_between(&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;"&amp;amp;today."d&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;, stop_date),&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;I have not heard of a months_between function so I used the intck function.&amp;nbsp; The code received yields these results&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Output &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; months&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;1123&amp;nbsp;&amp;nbsp; 6jun2014&amp;nbsp;&amp;nbsp;&amp;nbsp; 45.61&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;1124&amp;nbsp;&amp;nbsp; 28dec2017&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3.23&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;It appears the above code rounds down and sends two decimal places.&amp;nbsp; I am attempting to determine how to replicate these exact numbers.&amp;nbsp; The analyst that prepared this code is no longer available&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 19:57:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rounding-issue-in-datastep/m-p/451299#M113740</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2018-04-04T19:57:13Z</dc:date>
    </item>
    <item>
      <title>Re: Rounding issue in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rounding-issue-in-datastep/m-p/451308#M113743</link>
      <description>&lt;P&gt;First, you haven't shared with us variable STOP_DATE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, the concept of fractional months is something I would avoid like the plague. You'd have to handle months of 28, 29, 30 and 31 days properly, and even if you did that, the interpretation of fractional months is meaningless (is 18.5 months equal to 18 months and&amp;nbsp;14 days, or 18 months and&amp;nbsp;15 days, or 18 months and 15.5 days?) What a mess.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 20:21:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rounding-issue-in-datastep/m-p/451308#M113743</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-04-04T20:21:55Z</dc:date>
    </item>
    <item>
      <title>Re: Rounding issue in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rounding-issue-in-datastep/m-p/451315#M113745</link>
      <description>&lt;P&gt;The months_between() function is most probably custom made and returns a bogus value. Bogus for the reasons &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;gave.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 21:04:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rounding-issue-in-datastep/m-p/451315#M113745</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-04T21:04:17Z</dc:date>
    </item>
    <item>
      <title>Re: Rounding issue in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rounding-issue-in-datastep/m-p/451320#M113746</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, it certainly is not a SAS function, but it is an Oracle/PLSQL function (and probably exists in other languages as well).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.techonthenet.com/oracle/functions/months_between.php" target="_blank"&gt;https://www.techonthenet.com/oracle/functions/months_between.php&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it says right there that if a fractional month is calculated, a 31-day month is assumed, but it's still not clear what good that is if your time period has months of different lengths, interpretation again becomes a problem.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 21:36:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rounding-issue-in-datastep/m-p/451320#M113746</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-04-04T21:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: Rounding issue in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rounding-issue-in-datastep/m-p/451329#M113751</link>
      <description>&lt;P&gt;Using a 2-decimals correct value of the average month&amp;nbsp;duration you get:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
format stop_date yymmdd10.;
input ln_no $ stop_date date9. ;
datalines;
1123 16jun2014
1124 28dec2017
;

data want;
set have;
intMonths = intck("month", stop_date, today(), "continuous");
months = round( intMonths + 
    intck("day", 
        intnx("month", stop_date, intMonths, "same"), today()) * 12 / 365.25 , 0.01);
drop intMonths;
run;

proc print; run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;                        Obs     stop_date    ln_no    months

                         1     2014-06-16    1123      45.62
                         2     2017-12-28    1124       3.23
&lt;/PRE&gt;
&lt;P&gt;As calculated on the 4th of April 2018.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 22:13:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rounding-issue-in-datastep/m-p/451329#M113751</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-04-04T22:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: Rounding issue in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rounding-issue-in-datastep/m-p/451333#M113754</link>
      <description>&lt;P&gt;And rounding the number of months returned to the nearest multiple of 2 as well? Very interesting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you are not aware that the intck and intnx functions can use multiples. Also Intck has two different methods of comparison, Continuous or Discrete with Discrete the default. The following generates the number of "two month" intervals using default and both methods explicitly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
   format stop_date date9.;
   input ln_no $ stop_date date9. ;
   months  = intck('Month2',stop_date,"4apr2018"d);
   months2 = intck('Month2',stop_date,"4apr2018"d,'C');
   months3 = intck('Month2',stop_date,"4apr2018"d,'D');
datalines;
1123 16jun2014
1124 28dec2017
;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Apr 2018 22:18:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rounding-issue-in-datastep/m-p/451333#M113754</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-04-04T22:18:58Z</dc:date>
    </item>
  </channel>
</rss>

