<?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: Really basic question! in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/264125#M51771</link>
    <description>Superb, thanks!</description>
    <pubDate>Fri, 15 Apr 2016 10:28:45 GMT</pubDate>
    <dc:creator>Enio</dc:creator>
    <dc:date>2016-04-15T10:28:45Z</dc:date>
    <item>
      <title>Really basic question!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/263914#M51684</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I cannot get SAS to sum two long integers, I've tried numerous formats each to no avail. Problem is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format x bestx64.;
x = sum(9014242673057788,11016614466661);&lt;/CODE&gt;&lt;/PRE&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;x should equal (I think) 9025259287524449, but SAS returns 9025259287524448&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2016 16:07:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/263914#M51684</guid>
      <dc:creator>Enio</dc:creator>
      <dc:date>2016-04-14T16:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: Really basic question!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/263915#M51685</link>
      <description>I think taht the numbers are just to high. See SAS doc and numerical precission for you operating environment. &lt;BR /&gt;Is this a real life example?</description>
      <pubDate>Thu, 14 Apr 2016 16:14:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/263915#M51685</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-04-14T16:14:08Z</dc:date>
    </item>
    <item>
      <title>Re: Really basic question!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/263945#M51695</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/72792"&gt;@Enio﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think, LinusH is perfectly right. You're probably working on a Windows or Unix machine, aren't you? Please see the table "&lt;EM&gt;Largest Integer That Can Be Safely Stored in a Given Length&lt;/EM&gt;" in "&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#p0ji1unv6thm0dn1gp4t01a1u0g6.htm" target="_blank"&gt;Numerical&amp;nbsp;Accuracy in SAS Software&lt;/A&gt;". There you see that your first argument to the SUM function is slightly larger than the largest integer t&lt;SPAN&gt;hat can be "safely stored" in a numeric variable of maximum length (i.e. 8 bytes) on Windows/Unix systems. The result of the summation is, of course, even larger.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;To understand what's happening and how SAS obtains&amp;nbsp;9025259287524448, read the document linked above. Here's another technical paper on the subject:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;A href="http://support.sas.com/resources/papers/dealing-with-numeric-representation-error-in-sas-applications.pdf" target="_blank"&gt;Dealing with Numeric Representation Error in SAS® Applications&lt;/A&gt;.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2016 17:27:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/263945#M51695</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-14T17:27:14Z</dc:date>
    </item>
    <item>
      <title>Re: Really basic question!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/263947#M51696</link>
      <description>&lt;P&gt;The first number in your SUM function is just a hair larger than the maximum 8-byte integer in SAS, which is 9,007,199,254,740,992.&amp;nbsp; There's a SAS support article called &lt;A href="http://Refer to this documentation  http" target="_self"&gt;Numerical Accuracy in SAS Software&lt;/A&gt; that may be helpful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, here is one way to do it, although the result will be a character string, not actual numerical data.&amp;nbsp; It's admittedly a bit of a hack, but I'm basically breaking off the last 10 digits of each number, adding them separately, then adding the parts before the last 10 digits separately, and then concatenating the resulting sums as one long string:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data temp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;a1 = 901424;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;a2 = 2673057788;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;b1 = 1101;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;b2 = 6614466661;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;x1 = a1+b1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;x2 = a2+b2;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;sum = cats(put(x1,10.),put(x2,10.));&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that a1 and a2 represent the two parts of your first number, b1 and b2 are the two part of your second number, and x1 and x2 are the two parts of the answer.&amp;nbsp; Choosing 10 digits was somewhat arbitrary, but it keeps you well under the maximum allowable integer.&amp;nbsp; Obviously, if your numbers got much bigger, you might have to split into more parts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit to add: As noted below, this method only works if you break both numbers in a place where no carrying will occur, so it's really not an acceptable solution in general.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2016 19:41:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/263947#M51696</guid>
      <dc:creator>jmhorstman</dc:creator>
      <dc:date>2016-04-14T19:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: Really basic question!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/263955#M51698</link>
      <description>&lt;P&gt;It should be noted that the "concatenation method" proposed by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/43560"&gt;@jmhorstman﻿&lt;/a&gt;&amp;nbsp;does not generalize well:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Change only one digit in the first number&lt;/P&gt;
&lt;PRE&gt;901424&lt;FONT color="#FF0000"&gt;3&lt;/FONT&gt;673057788&lt;/PRE&gt;
&lt;P&gt;and you get a nonsense result (off by a factor of almost 10!).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2016 17:40:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/263955#M51698</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-14T17:40:27Z</dc:date>
    </item>
    <item>
      <title>Re: Really basic question!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/263956#M51699</link>
      <description>&lt;P&gt;OK, yeah, good point &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;, because the carrying doesn't work out.&amp;nbsp; Guess I got lucky the first time.&amp;nbsp; Additional logic could be added to deal with that possibility, but it could get pretty ugly if the carrying cascades all the way left.&amp;nbsp; Like I said, it was a hack anyway.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2016 17:42:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/263956#M51699</guid>
      <dc:creator>jmhorstman</dc:creator>
      <dc:date>2016-04-14T17:42:32Z</dc:date>
    </item>
    <item>
      <title>Re: Really basic question!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/263976#M51709</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;49         proc ds2;
50            data _null_;
51               declare bigint x y z;
52               method run();
53                  x=9014242673057788;
54                  y=11016614466661;
55                  z=y+x;
56                  put _all_;
57                  end;
58               enddata;
59            run;
_N_=1 x=9014242673057788 y=11016614466661 z=9025259287524449&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Apr 2016 19:05:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/263976#M51709</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-04-14T19:05:52Z</dc:date>
    </item>
    <item>
      <title>Re: Really basic question!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/264010#M51722</link>
      <description>&lt;P&gt;Hi Team&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have IML you can call R or use my macro&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%utl_submit_r64(%nrbquote(&lt;BR /&gt;library(gmp);&lt;BR /&gt;e1 &amp;lt;- as.bigz("1111111111111111111111111111111111111111");&lt;BR /&gt;e2 &amp;lt;- as.bigz("2222222222222222222222222222222222222222");&lt;BR /&gt;add.bigz(e1, e2);&lt;BR /&gt;));&lt;BR /&gt;Big Integer ('bigz') :&lt;BR /&gt;[1] 3333333333333333333333333333333333333333&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think there are at least a dozen operators in the gmp package, in addition to add.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Python has this builtin?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;R can read sas7bdats and output almost any format. I like to use MS-Access and stata because they are lossless and allow long variable names and char vars over 200bytes.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2016 20:35:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/264010#M51722</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2016-04-14T20:35:42Z</dc:date>
    </item>
    <item>
      <title>Re: Really basic question!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/264045#M51735</link>
      <description>DS2 also has a bigint type.</description>
      <pubDate>Fri, 15 Apr 2016 00:12:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/264045#M51735</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-15T00:12:51Z</dc:date>
    </item>
    <item>
      <title>Re: Really basic question!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/264087#M51756</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; wrote:&lt;BR /&gt;DS2 also has a bigint type.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;But the problem will arise again if the user tries to store those values in SAS datasets. One will probably have to store them as character and reconvert to bigint for further calculations. Or use a bigint-capable DBMS for storage.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Apr 2016 06:12:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/264087#M51756</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-04-15T06:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: Really basic question!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/264124#M51770</link>
      <description>&lt;P&gt;Slightly off topic, but I once investigated extended-precision operations (by hand, not automatically) in SAS. See the article&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.sas.com/content/iml/2011/01/25/computing-200-factorial-using-proc-iml-as-a-really-big-calculator.html" target="_self"&gt;"Computing 200 factorial: Using PROC IML as a really BIG calculator"&lt;/A&gt;&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/15410"&gt;@data_null__﻿&lt;/a&gt;&amp;nbsp;has the best solution (DS2) if you need big integers in a real work-related computation.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Apr 2016 10:11:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/264124#M51770</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-04-15T10:11:38Z</dc:date>
    </item>
    <item>
      <title>Re: Really basic question!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/264125#M51771</link>
      <description>Superb, thanks!</description>
      <pubDate>Fri, 15 Apr 2016 10:28:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/264125#M51771</guid>
      <dc:creator>Enio</dc:creator>
      <dc:date>2016-04-15T10:28:45Z</dc:date>
    </item>
    <item>
      <title>Re: Really basic question!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/264126#M51772</link>
      <description>Many thanks. You're quite right, there are some downstream sections to this process which will have to use bigint-capable DBMS as they are not able to utilise PROC DS2. Appreciate you taking the time to add this.</description>
      <pubDate>Fri, 15 Apr 2016 10:31:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Really-basic-question/m-p/264126#M51772</guid>
      <dc:creator>Enio</dc:creator>
      <dc:date>2016-04-15T10:31:25Z</dc:date>
    </item>
  </channel>
</rss>

