<?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: Strange behavior of long int in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-of-long-int-in-SAS/m-p/609408#M177428</link>
    <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp; , &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp; and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;</description>
    <pubDate>Wed, 04 Dec 2019 15:08:32 GMT</pubDate>
    <dc:creator>arunrami</dc:creator>
    <dc:date>2019-12-04T15:08:32Z</dc:date>
    <item>
      <title>Strange behavior of long int in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-of-long-int-in-SAS/m-p/609354#M177408</link>
      <description>&lt;P&gt;&lt;FONT&gt;Hi SASians,&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;I have noticed something weird today while using long int in SAS dataset, it is getting printed slightly different value&lt;BR /&gt;even after using format . I believed this is something related to scientific notation&amp;nbsp; E to real value goes wrong in PDV ..&lt;BR /&gt;or am I missing something here ??&lt;BR /&gt;Any suggestion and why it is like that ?&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;data dummy;&lt;BR /&gt;infile cards;&lt;BR /&gt;input a 30.;&lt;BR /&gt;format a 30.;&lt;BR /&gt;cards;&lt;BR /&gt;231512182813021801&lt;BR /&gt;run;&lt;BR /&gt;getting 231512182813021792 , expected value 231512182813021801.&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;Regards,&lt;BR /&gt;SAR&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 12:47:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-of-long-int-in-SAS/m-p/609354#M177408</guid>
      <dc:creator>arunrami</dc:creator>
      <dc:date>2019-12-04T12:47:43Z</dc:date>
    </item>
    <item>
      <title>Re: Strange behavior of long int in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-of-long-int-in-SAS/m-p/609356#M177409</link>
      <description>&lt;P&gt;SAS does not have the datatype longint (except in some special circumstances).&lt;/P&gt;
&lt;P&gt;SAS stores all numbers in 8-byte real, which means that the maximum precision is about 15 decimal digits, and that causes the effect you see here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For statistical analysis, such precision is not needed, and if you have something that is not in fact a number, but some kind of code (eg telephone numbers or SSN), you are better off storing it as character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/200330"&gt;@arunrami&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;FONT&gt;Hi SASians,&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;I have noticed something weird today while using long int in SAS dataset, it is getting printed slightly different value&lt;BR /&gt;even after using format . I believed this is something related to scientific notation&amp;nbsp; E to real value goes wrong in PDV ..&lt;BR /&gt;or am I missing something here ??&lt;BR /&gt;Any suggestion and why it is like that ?&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;data dummy;&lt;BR /&gt;infile cards;&lt;BR /&gt;input a 30.;&lt;BR /&gt;format a 30.;&lt;BR /&gt;cards;&lt;BR /&gt;231512182813021801&lt;BR /&gt;run;&lt;BR /&gt;getting 231512182813021792 , expected value 231512182813021801.&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;Regards,&lt;BR /&gt;SAR&lt;/FONT&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 12:54:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-of-long-int-in-SAS/m-p/609356#M177409</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-04T12:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: Strange behavior of long int in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-of-long-int-in-SAS/m-p/609360#M177411</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The&amp;nbsp;&lt;SPAN&gt;9,007,199,254,740,992 is max what SAS can store in 8 bytes on WIN or Linux. Please see the doc here:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p0ji1unv6thm0dn1gp4t01a1u0g6.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p0ji1unv6thm0dn1gp4t01a1u0g6.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;for details (section "Maximum Integer Size").&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;All the best&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Bart&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 13:04:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-of-long-int-in-SAS/m-p/609360#M177411</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2019-12-04T13:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: Strange behavior of long int in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-of-long-int-in-SAS/m-p/609376#M177414</link>
      <description>&lt;P&gt;Thanks for the reponse&lt;/P&gt;&lt;P&gt;, but I really want it as a number and also am fetching from database hence it would be better if I can store and see the result as it is..&lt;/P&gt;&lt;P&gt;and converting the datatype to character also doesn't seem to be solving the problem..find here&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;data fil;&lt;BR /&gt;set dummy;&lt;BR /&gt;b = put(a,20.);&amp;nbsp;&lt;BR /&gt;where a = 231512182813021801 ;&lt;BR /&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is there any other way to read and print these kind of as it is ?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 13:29:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-of-long-int-in-SAS/m-p/609376#M177414</guid>
      <dc:creator>arunrami</dc:creator>
      <dc:date>2019-12-04T13:29:11Z</dc:date>
    </item>
    <item>
      <title>Re: Strange behavior of long int in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-of-long-int-in-SAS/m-p/609380#M177415</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/200330"&gt;@arunrami&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for the reponse&lt;/P&gt;
&lt;P&gt;, but I really want it as a number and also am fetching from database hence it would be better if I can store and see the result as it is..&lt;/P&gt;
&lt;P&gt;and converting the datatype to character also doesn't seem to be solving the problem..find here&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;data fil;&lt;BR /&gt;set dummy;&lt;BR /&gt;b = put(a,20.);&amp;nbsp;&lt;BR /&gt;where a = 231512182813021801 ;&lt;BR /&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is there any other way to read and print these kind of as it is ?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Well, a has already lost precision, so converting it within SAS is useless. You need to import it as character in the first place.&lt;/P&gt;
&lt;P&gt;And, as I already said, if it IS a number, such precision makes no sense in a statistics environment. It's another thing if you need the GDP of the USA down to cents, but we're not doing the national accounting here &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 13:43:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-of-long-int-in-SAS/m-p/609380#M177415</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-04T13:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: Strange behavior of long int in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-of-long-int-in-SAS/m-p/609381#M177416</link>
      <description>I got your point, it may not be significant when using it for statistics!,&lt;BR /&gt;but considering reporting, like taking data from source(for which we dont have any write access and just creating some report out of it, precision does matter !!&lt;BR /&gt;&lt;BR /&gt;And I noted that value stored as an actual one in SAS memory , poroblem is only when I try to print/see it in dataset &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;</description>
      <pubDate>Wed, 04 Dec 2019 13:51:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-of-long-int-in-SAS/m-p/609381#M177416</guid>
      <dc:creator>arunrami</dc:creator>
      <dc:date>2019-12-04T13:51:27Z</dc:date>
    </item>
    <item>
      <title>Re: Strange behavior of long int in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-of-long-int-in-SAS/m-p/609394#M177422</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/200330"&gt;@arunrami&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are the details of what SAS did to your numeric literal &lt;SPAN&gt;231512182813021801&lt;/SPAN&gt; (assuming a Windows or Unix operating system):&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Write the original integer in the binary system (e.g., the Windows calculator calc.exe can do this conversion):&lt;BR /&gt;
&lt;PRE&gt;1100110110011111110001101010001001101111101101011001101001&lt;/PRE&gt;
Note that it has 58 binary digits.&lt;/LI&gt;
&lt;LI&gt;Round the number to &lt;STRONG&gt;53&lt;/STRONG&gt; significant binary digits:&lt;BR /&gt;
&lt;PRE&gt;&lt;STRONG&gt;11001101100111111100011010100010011011111011010110011&lt;/STRONG&gt;00000&lt;/PRE&gt;
The last 58−53=5 original binary digits, &lt;FONT face="courier new,courier"&gt;01001&lt;/FONT&gt;, started with &lt;EM&gt;0&lt;/EM&gt; and hence have been rounded &lt;EM&gt;down&lt;/EM&gt;. (This has the same effect as subtracting &lt;FONT face="courier new,courier"&gt;01001&lt;/FONT&gt;, i.e. 9 in the decimal system, from the original number.)&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;Convert the number back to the decimal system. (Again, the Windows calculator can do this, but alternatively you can just add/subtract the amount by which the original number has been rounded up/down, see item 2: ...1801−9=...1792.)&lt;BR /&gt;
&lt;PRE&gt;231512182813021792&lt;/PRE&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;The 53 bits mentioned in item 2 are the so called "implied bit" plus the 52 mantissa bits which SAS stores internally besides the 1+11 bits for the sign and exponent, respectively (see&amp;nbsp;&lt;A href="https://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p0ji1unv6thm0dn1gp4t01a1u0g6.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;Numerical Accuracy in SAS Software&lt;/A&gt;&amp;nbsp;[linked by &lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763" target="_blank" rel="noopener"&gt;yabwon&lt;/A&gt; already] for more details).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To avoid the loss of precision, you should store integers of this size in character variables, as &lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562" target="_blank" rel="noopener"&gt;Kurt Bremser&lt;/A&gt; has recommended. Using PROC DS2 or PROC FedSQL you can still handle them (up to certain limits, see &lt;A href="https://documentation.sas.com/?docsetId=ds2pg&amp;amp;docsetTarget=n0v130wmh3hmuzn1t7y5y4pgxa69.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;BIGINT data type&lt;/A&gt;) as numeric values: see the old thread &lt;A href="https://communities.sas.com/t5/SAS-Programming/Convert-large-number/m-p/581328/highlight/true#M165213" target="_blank" rel="noopener"&gt;Convert large number&lt;/A&gt; for an example. Certain calculations can even be done digit by digit in a DATA step (example: &lt;A href="https://communities.sas.com/t5/New-SAS-User/Mod-function-with-big-number/m-p/546610#M8240" target="_blank" rel="noopener"&gt;Mod function with big number&lt;/A&gt;).&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 14:33:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-of-long-int-in-SAS/m-p/609394#M177422</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-12-04T14:33:00Z</dc:date>
    </item>
    <item>
      <title>Re: Strange behavior of long int in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-of-long-int-in-SAS/m-p/609408#M177428</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp; , &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp; and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 15:08:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-of-long-int-in-SAS/m-p/609408#M177428</guid>
      <dc:creator>arunrami</dc:creator>
      <dc:date>2019-12-04T15:08:32Z</dc:date>
    </item>
  </channel>
</rss>

