<?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: input function doesn't work with long strings in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/input-function-doesn-t-work-with-long-strings/m-p/746304#M234103</link>
    <description>&lt;P&gt;What are you measuring or counting that requires 32 significant digits?&lt;/P&gt;</description>
    <pubDate>Mon, 07 Jun 2021 16:28:50 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-06-07T16:28:50Z</dc:date>
    <item>
      <title>input function doesn't work with long strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/input-function-doesn-t-work-with-long-strings/m-p/746292#M234099</link>
      <description>&lt;P&gt;in my work I have strings that contain only digits. Very long strings up to 32 characters.&lt;BR /&gt;If I use the function input() to convert from character to numeric, but with strings longer than 16 characters the numeric result is visibly wrong. I include the code explaining the problem, and the printout of the results. Can anyone explain to me where am I wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA TEST_INPUT ;&lt;BR /&gt;INPUT CHAR_TEXT $32. ;&lt;BR /&gt;DATALINES;&lt;BR /&gt;3659218487881310922172417 &lt;BR /&gt;3662444754643708821993473&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;RUN ;&lt;/P&gt;
&lt;P&gt;DATA TEST_INPUT2 ;&lt;BR /&gt;SET TEST_INPUT ;&lt;BR /&gt;FORMAT CHAR_2_NUM 32. ;&lt;BR /&gt;FORMAT CHAR_2_NUM_16_DIGIT 32. ;&lt;BR /&gt;FORMAT CHAR_2_NUM_17_DIGIT 32.;&lt;BR /&gt;CHAR_2_NUM = INPUT(CHAR_TEXT,32.);&lt;BR /&gt;CHAR_2_NUM_16_DIGIT =INPUT(SUBSTR(CHAR_TEXT,1,16),32.);&lt;BR /&gt;CHAR_2_NUM_17_DIGIT =INPUT(SUBSTR(CHAR_TEXT,1,17),32.);&lt;BR /&gt;RUN ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TD width="175"&gt;
&lt;P&gt;NUMB_TEXT&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="175"&gt;
&lt;P&gt;CHAR_2_NUM&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="181"&gt;
&lt;P&gt;CHAR_2_NUM_16_DIGIT&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="181"&gt;
&lt;P&gt;CHAR_2_NUM_17_DIGIT&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="175"&gt;
&lt;P&gt;3659218487881310922172417&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="175"&gt;
&lt;P&gt;3659218487881310752735232&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="181"&gt;
&lt;P&gt;3659218487881310&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="181"&gt;
&lt;P&gt;36592184878813112&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="175"&gt;
&lt;P&gt;3662444754643708821993473&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="175"&gt;
&lt;P&gt;3662444754643709451042816&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="181"&gt;
&lt;P&gt;3662444754643708&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="181"&gt;
&lt;P&gt;36624447546437088&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Mon, 07 Jun 2021 16:13:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/input-function-doesn-t-work-with-long-strings/m-p/746292#M234099</guid>
      <dc:creator>prizzo60</dc:creator>
      <dc:date>2021-06-07T16:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: input function doesn't work with long strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/input-function-doesn-t-work-with-long-strings/m-p/746299#M234101</link>
      <description>SAS (and many other applications including Excel) cannot store numeric values beyond 16 digits. &lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/hostunx/p12zsdbylnn6c2n1i48z7djr6uzo.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/hostunx/p12zsdbylnn6c2n1i48z7djr6uzo.htm&lt;/A&gt;</description>
      <pubDate>Mon, 07 Jun 2021 16:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/input-function-doesn-t-work-with-long-strings/m-p/746299#M234101</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-07T16:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: input function doesn't work with long strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/input-function-doesn-t-work-with-long-strings/m-p/746303#M234102</link>
      <description>&lt;P&gt;As I recall 2 to the 52nd power (2**52) or&amp;nbsp;4,503,599,627,370,496 is the largest number the current release of SAS can contain without loss of precision.&amp;nbsp; SAS is all double precision floating point binary in terms of numeric representation.&amp;nbsp; It doesn't have BIGINT or DECIMAL or other formats that might handle larger numbers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jun 2021 16:26:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/input-function-doesn-t-work-with-long-strings/m-p/746303#M234102</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-06-07T16:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: input function doesn't work with long strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/input-function-doesn-t-work-with-long-strings/m-p/746304#M234103</link>
      <description>&lt;P&gt;What are you measuring or counting that requires 32 significant digits?&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jun 2021 16:28:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/input-function-doesn-t-work-with-long-strings/m-p/746304#M234103</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-07T16:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: input function doesn't work with long strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/input-function-doesn-t-work-with-long-strings/m-p/746316#M234107</link>
      <description>I agree , it is very strange number with 32 significant digits, but this number is a "serial number" deriving from contract in stock market.</description>
      <pubDate>Mon, 07 Jun 2021 16:57:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/input-function-doesn-t-work-with-long-strings/m-p/746316#M234107</guid>
      <dc:creator>prizzo60</dc:creator>
      <dc:date>2021-06-07T16:57:35Z</dc:date>
    </item>
    <item>
      <title>Re: input function doesn't work with long strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/input-function-doesn-t-work-with-long-strings/m-p/746318#M234108</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31830"&gt;@prizzo60&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To store your example 25-digit strings (or even 32-digit strings) in numeric variables &lt;EM&gt;without losing precision&lt;/EM&gt;, SAS under Windows or Unix would need 81 (106) mantissa bits -- i.e., 29 (54) more than are available.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Strange-behavior-of-long-int-in-SAS/m-p/609394/highlight/true#M177422" target="_blank" rel="noopener"&gt;Re: Strange behavior of long int in SAS&lt;/A&gt; for explanations and additional links.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would store these "numbers" in a character variable of sufficient length (and look forward to coding the algorithms needed to perform calculations with them, if any).&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jun 2021 17:12:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/input-function-doesn-t-work-with-long-strings/m-p/746318#M234108</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-06-07T17:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: input function doesn't work with long strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/input-function-doesn-t-work-with-long-strings/m-p/746320#M234109</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31830"&gt;@prizzo60&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I agree , it is very strange number with 32 significant digits, but this number is a "serial number" deriving from contract in stock market.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you aren't doing arithmetic with the variable it should be character.&lt;/P&gt;
&lt;P&gt;Any sequential behavior of a "serial number" would maintain an you won't lose any information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Account numbers, addresses, phone numbers, part numbers: character.&lt;/P&gt;
&lt;P&gt;Height , weight, currency values, counts or measurements with units: numeric.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jun 2021 17:13:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/input-function-doesn-t-work-with-long-strings/m-p/746320#M234109</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-07T17:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: input function doesn't work with long strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/input-function-doesn-t-work-with-long-strings/m-p/746332#M234112</link>
      <description>Then if you're not doing math with it, you can store it as a character. &lt;BR /&gt;If you need specific portions for identifiers then you can parse them out into separate fields.</description>
      <pubDate>Mon, 07 Jun 2021 18:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/input-function-doesn-t-work-with-long-strings/m-p/746332#M234112</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-07T18:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: input function doesn't work with long strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/input-function-doesn-t-work-with-long-strings/m-p/746338#M234116</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31830"&gt;@prizzo60&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I agree , it is very strange number with 32 significant digits, but this number is a "serial number" deriving from contract in stock market.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then it will never be used in calculations, so store it as a character string. Just like we do with our policy "numbers".&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jun 2021 18:19:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/input-function-doesn-t-work-with-long-strings/m-p/746338#M234116</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-07T18:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: input function doesn't work with long strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/input-function-doesn-t-work-with-long-strings/m-p/746374#M234132</link>
      <description>&lt;P&gt;The only thing I would add to all the comments to keep this variable in character format is to make sure that the value is right-justified. I.e. any value with fewer characters should have leading blanks not trailing blanks. This will preserve a sort order identical to what would be the case if you had sufficiently precise numeric values. &lt;BR /&gt;&lt;BR /&gt;Or you might insert leading zeroes to eliminate blanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Added note:&amp;nbsp; If you don't right justify and allow trailing blanks, then sorting on these values will produce lexicographic ordering (i.e. '1111' is less than '22&amp;nbsp; '), rather than ordering by the implicit value (i.e. '&amp;nbsp; 22' is less than '1111').&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 03:12:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/input-function-doesn-t-work-with-long-strings/m-p/746374#M234132</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-06-08T03:12:19Z</dc:date>
    </item>
  </channel>
</rss>

