<?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: Can I extend the default length of the number of digits to over 16 for numeric variables? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Can-I-extend-the-default-length-of-the-number-of-digits-to-over/m-p/857536#M37826</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439259"&gt;@Esreg&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Numeric variables in SAS datasets have a length of up to 8 bytes. Even the BIGINT type mentioned by &lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684" target="_blank" rel="noopener"&gt;Rick_SAS&lt;/A&gt; is limited to 8 bytes. The set of positive 21-digit decimal integers (i.e. from &lt;FONT face="courier new,courier"&gt;1E20&lt;/FONT&gt; through &lt;FONT face="courier new,courier"&gt;1E21-1&lt;/FONT&gt;) comprises &lt;FONT face="courier new,courier"&gt;9E20&lt;/FONT&gt; numbers. Eight bytes (= 64 bit), however, can only store up to &lt;FONT face="courier new,courier"&gt;2**64=1.84&lt;/FONT&gt;...&lt;FONT face="courier new,courier"&gt;E&lt;STRONG&gt;19&lt;/STRONG&gt;&lt;/FONT&gt; distinct values, regardless of the hardware or software platform used. So it is impossible to represent all those &lt;FONT face="courier new,courier"&gt;9E20&lt;/FONT&gt; numbers with an 8-byte variable of any sort. Trying to store such a number in a numeric variable typically leads to a rounded or truncated internal binary representation, which results in decimal numbers ending in seemingly "random" digits, as you have noticed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really need to perform certain calculations with those long integers, there are workarounds available:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Split the CRDNO values into two shorter digit strings (of less than 16 digits), store these in &lt;EM&gt;two&lt;/EM&gt; numeric variables and write code to perform the calculations using the two parts of the numbers.&lt;/LI&gt;
&lt;LI&gt;Store the CRDNO values in a &lt;EM&gt;character&lt;/EM&gt; variable and perform the calculations on a digit-by-digit basis in SAS (examples:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/New-SAS-User/Mod-function-with-big-number/m-p/546610/highlight/true#M8240" target="_blank" rel="noopener"&gt;Mod function with big number&lt;/A&gt;, &lt;A href="https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653973/highlight/true#M196445" target="_blank" rel="noopener"&gt;base conversion&lt;/A&gt;) or by calling external modules written in other languages.
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;/UL&gt;</description>
    <pubDate>Tue, 07 Feb 2023 13:09:09 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2023-02-07T13:09:09Z</dc:date>
    <item>
      <title>Can I extend the default length of the number of digits to over 16 for numeric variables?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-I-extend-the-default-length-of-the-number-of-digits-to-over/m-p/857524#M37824</link>
      <description>&lt;P&gt;For numeric variables in SAS, for numbers greater than 16th numeric value it shows different values - SAS can only read up to 16 decimal digits and the rest of the digits will be generated randomly. Is there a way to change the default length of the readable numeric digits?&lt;/P&gt;&lt;P&gt;I would like to retain the variable as numeric not character, and I would like to extend the number of digits beyond 16.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data demo1;&lt;BR /&gt;input CRDNO ;&lt;BR /&gt;FORMAT CRDNO BEST21.;&lt;BR /&gt;CARDS;&lt;BR /&gt;123456789123456791234&lt;BR /&gt;111111111111111111111111&lt;/P&gt;&lt;P&gt;222222222222222222222&lt;BR /&gt;RUN;&lt;BR /&gt;proc print;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS&amp;nbsp;output will show only up to 16 numeric value but greater than 16th numeric value it shows different values. And I believe the last few digits of the numbers are random.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Obs&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;CRDNO&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;123456789123456794624&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;111111111111111114752&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;3&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;222222222222222229504&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 07 Feb 2023 13:23:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-I-extend-the-default-length-of-the-number-of-digits-to-over/m-p/857524#M37824</guid>
      <dc:creator>Esreg</dc:creator>
      <dc:date>2023-02-07T13:23:11Z</dc:date>
    </item>
    <item>
      <title>Re: Can I extend the default length of the number of digits to over 16 for numeric variables?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-I-extend-the-default-length-of-the-number-of-digits-to-over/m-p/857530#M37825</link>
      <description>&lt;P&gt;In the DATA step, people often read big integers (such as SSN numbers or bank accounts) as character values. In general, if the number is an identifier and you do not intend to perform arithmetic on it, then read it as a character variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DS2 procedure supports the BIGINT (Int64 = 64-bit integers), as does the CAS server. See&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/ds2pg/n0v130wmh3hmuzn1t7y5y4pgxa69.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/ds2pg/n0v130wmh3hmuzn1t7y5y4pgxa69.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/ds2pg/p0x19g0gas4lvtn1o48uba5wq1vd.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/ds2pg/p0x19g0gas4lvtn1o48uba5wq1vd.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;:&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you search the internet for "SAS BIGINT type" you can find additional information and discussion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 11:53:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-I-extend-the-default-length-of-the-number-of-digits-to-over/m-p/857530#M37825</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2023-02-07T11:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: Can I extend the default length of the number of digits to over 16 for numeric variables?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-I-extend-the-default-length-of-the-number-of-digits-to-over/m-p/857536#M37826</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439259"&gt;@Esreg&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Numeric variables in SAS datasets have a length of up to 8 bytes. Even the BIGINT type mentioned by &lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684" target="_blank" rel="noopener"&gt;Rick_SAS&lt;/A&gt; is limited to 8 bytes. The set of positive 21-digit decimal integers (i.e. from &lt;FONT face="courier new,courier"&gt;1E20&lt;/FONT&gt; through &lt;FONT face="courier new,courier"&gt;1E21-1&lt;/FONT&gt;) comprises &lt;FONT face="courier new,courier"&gt;9E20&lt;/FONT&gt; numbers. Eight bytes (= 64 bit), however, can only store up to &lt;FONT face="courier new,courier"&gt;2**64=1.84&lt;/FONT&gt;...&lt;FONT face="courier new,courier"&gt;E&lt;STRONG&gt;19&lt;/STRONG&gt;&lt;/FONT&gt; distinct values, regardless of the hardware or software platform used. So it is impossible to represent all those &lt;FONT face="courier new,courier"&gt;9E20&lt;/FONT&gt; numbers with an 8-byte variable of any sort. Trying to store such a number in a numeric variable typically leads to a rounded or truncated internal binary representation, which results in decimal numbers ending in seemingly "random" digits, as you have noticed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really need to perform certain calculations with those long integers, there are workarounds available:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Split the CRDNO values into two shorter digit strings (of less than 16 digits), store these in &lt;EM&gt;two&lt;/EM&gt; numeric variables and write code to perform the calculations using the two parts of the numbers.&lt;/LI&gt;
&lt;LI&gt;Store the CRDNO values in a &lt;EM&gt;character&lt;/EM&gt; variable and perform the calculations on a digit-by-digit basis in SAS (examples:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/New-SAS-User/Mod-function-with-big-number/m-p/546610/highlight/true#M8240" target="_blank" rel="noopener"&gt;Mod function with big number&lt;/A&gt;, &lt;A href="https://communities.sas.com/t5/SAS-Programming/Converting-a-19-length-number-to-hex-and-then-to-a-string/m-p/653973/highlight/true#M196445" target="_blank" rel="noopener"&gt;base conversion&lt;/A&gt;) or by calling external modules written in other languages.
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Tue, 07 Feb 2023 13:09:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-I-extend-the-default-length-of-the-number-of-digits-to-over/m-p/857536#M37826</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-02-07T13:09:09Z</dc:date>
    </item>
    <item>
      <title>Re: Can I extend the default length of the number of digits to over 16 for numeric variables?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-I-extend-the-default-length-of-the-number-of-digits-to-over/m-p/857642#M37830</link>
      <description>&lt;P&gt;Looks like you are reading credit card numbers. Since you won't be doing calculations on them there is absolutely no reason not to read them as character. I deal with credit card numbers all the time and we always define them as 16 characters.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 19:16:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-I-extend-the-default-length-of-the-number-of-digits-to-over/m-p/857642#M37830</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-02-07T19:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: Can I extend the default length of the number of digits to over 16 for numeric variables?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-I-extend-the-default-length-of-the-number-of-digits-to-over/m-p/857644#M37831</link>
      <description>&lt;P&gt;If that is a (credit) card number, it must always be stored as character. You won't do calculations with it.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 19:28:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-I-extend-the-default-length-of-the-number-of-digits-to-over/m-p/857644#M37831</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-07T19:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: Can I extend the default length of the number of digits to over 16 for numeric variables?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-I-extend-the-default-length-of-the-number-of-digits-to-over/m-p/857661#M37832</link>
      <description>&lt;P&gt;You can ask SAS to show you the largest integer it can store as a number before it you start seeing collisions of two or more integers to the same number.&lt;/P&gt;
&lt;PRE&gt;1757  data _null_;
1758    big=constant('exactint');
1759    put big :comma24.;
1760  run;

9,007,199,254,740,992
&lt;/PRE&gt;
&lt;P&gt;Any numbers longer than that you should store as character strings instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data demo1;
  input @1 String $21. @1 number ;
  put '_INFILE_: ' _infile_ :21.
    / 'STRING  : ' string 
    / 'NUMBER  : ' number 21. 
    / 
  ;
CARDS;
123456789012345678901
111111111111111111111
222222222222222222222
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;_INFILE_: 123456789012345678901
STRING  : 123456789012345678901
NUMBER  : 123456789012345683968

_INFILE_: 111111111111111111111
STRING  : 111111111111111111111
NUMBER  : 111111111111111114752

_INFILE_: 222222222222222222222
STRING  : 222222222222222222222
NUMBER  : 222222222222222229504
&lt;/PRE&gt;
&lt;P&gt;If you are reading your data from a text file, like a CSV file, then make sure to define the variable has character when you read it.&lt;/P&gt;
&lt;P&gt;If you are getting these values from an external database then have the database cast the value as a string before sending it to SAS.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 20:30:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-I-extend-the-default-length-of-the-number-of-digits-to-over/m-p/857661#M37832</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-07T20:30:16Z</dc:date>
    </item>
  </channel>
</rss>

