<?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 not converting character to numeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/INPUT-not-converting-character-to-numeric/m-p/981236#M379051</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/280176"&gt;@hubernomiddle&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Also just a side question, I left in a COL2 that when PROC IMPORT'ed, 0.07 gets converted to "7.0000000000000007E-2". I assume this is just floating point but not sure why this happens if it's being read as character.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The reason is that the numeric value is given as&lt;/P&gt;
&lt;PRE&gt;&amp;lt;v&amp;gt;7.0000000000000007E-2&amp;lt;/v&amp;gt;&lt;/PRE&gt;
&lt;P&gt;in the XML code which (in zipped form) is contained in your .xlsx file. I see also&lt;/P&gt;
&lt;PRE&gt;&amp;lt;v&amp;gt;2.0099999999999998&amp;lt;/v&amp;gt;&lt;/PRE&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;PRE&gt;&amp;lt;v&amp;gt;1.1000000000000001&amp;lt;/v&amp;gt;&lt;/PRE&gt;
&lt;P&gt;in there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In all three cases the small deviations from 0.07, 2.01 and 1.1, respectively, just reflect the unavoidable rounding errors of the binary floating-point representations of 0.07, 2.01 and 1.1 with 52 mantissa bits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If those values are read as &lt;EM&gt;numeric&lt;/EM&gt; values (using the INPUT statement, the INPUT function or assignment statements with those literals), SAS will regard them exactly equal to&amp;nbsp;0.07, 2.01 and 1.1, respectively, without further rounding -- which you could apply otherwise:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input x;
put x hex16.;
cards;
7.0000000000000007E-2
0.07
2.0099999999999998
2.01
1.1000000000000001
1.1  
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;3FB1EB851EB851EC
3FB1EB851EB851EC
4000147AE147AE14
4000147AE147AE14
3FF199999999999A
3FF199999999999A
&lt;/PRE&gt;</description>
    <pubDate>Tue, 23 Dec 2025 09:55:13 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2025-12-23T09:55:13Z</dc:date>
    <item>
      <title>INPUT not converting character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INPUT-not-converting-character-to-numeric/m-p/981218#M379048</link>
      <description>&lt;P&gt;I feel silly asking this question but for some reason, I am having issue with this particular dataset when converting character to numeric. See attached for the data I am running this on. This problem seems to only be happening with PROC IMPORT.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you don't want to download the file, the basic problem is that when importing an XLSX for columns with numeric values but the numeric values have a space after it, I am unable to convert the values to numeric.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC IMPORT DATAFILE="have.xlsx" DBMS=xlsx REPLACE OUT=have;
RUN;

DATA want;
    SET have;
    FORMAT col1 col2;
    INFORMAT col1 col2;
    col1_nothing=INPUT(col1,8.);
    col1_compress=INPUT(COMPRESS(col1),8.);
    col1_strip=INPUT(STRIP(col1),8.);
    col1_trim=INPUT(TRIM(col1),8.);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output is below:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hubertsng_0-1766429744842.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/112413i1FB59A75B52DB96F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hubertsng_0-1766429744842.png" alt="hubertsng_0-1766429744842.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All of the cells that are corresponding with a cell that is a numeric value followed by a space have an end result of numeric missing. Performing COMPRESS, TRIM, STRIP does not remove this space. This error does not occur when creating a dataset within SAS and only when importing with PROC IMPORT&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;DATA test;
    test="0.14 ";
    test2=INPUT(test,8.);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I know the solution is just editing the dataset but ideally, I'd like to fix this without manually editing data I am given for my position.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This error is occurring when run on SAS EG 8.6, SAS 9.4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also just a side question, I left in a COL2 that when PROC IMPORT'ed, 0.07 gets converted to "7.0000000000000007E-2". I assume this is just floating point but not sure why this happens if it's being read as character.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Dec 2025 19:02:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INPUT-not-converting-character-to-numeric/m-p/981218#M379048</guid>
      <dc:creator>hubernomiddle</dc:creator>
      <dc:date>2025-12-22T19:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: INPUT not converting character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INPUT-not-converting-character-to-numeric/m-p/981225#M379049</link>
      <description>&lt;P&gt;I did not download your spreadsheet. You can use &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt; to convert the output from PROC IMPORT into data step code we can use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Most likely, there is a non-printable (invisible) character(s) in F1 and thus the contents of F1 cannot be converted to a number. You can use the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/v_049/ds2ref/n01p24mgwawxa2n1hy4gwe5t59xf.htm" target="_self"&gt;COMPRESS function&lt;/A&gt; to remove characters you don't want, or keep characters you do want. In this case, we want to keep digits, the dot, and possibly commas and a hyphen to indicate a negative number. So this will do the job:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    f1_numeric=input(compress(f1,'.,-','dk'),best32.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Dec 2025 19:28:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INPUT-not-converting-character-to-numeric/m-p/981225#M379049</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-12-22T19:28:37Z</dc:date>
    </item>
    <item>
      <title>Re: INPUT not converting character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INPUT-not-converting-character-to-numeric/m-p/981227#M379050</link>
      <description>&lt;P&gt;Bah, running that code on my work PC gives me an error for insufficient authorization. I'll figure it out more next time I need help, this is helpful. I was surprised that this isn't built in on the SAS forums and did a print screen of the output (and subsequently input).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just ran that snippet you gave me on the compress and your hunch was correct. Thank you! I should've been ticked off on that possibility when I went to created a test dataset with "0.14 " but excel automatically formatted it as numeric without the leading blank so there was definitely something other than just a space in the original dataset.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Dec 2025 19:39:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INPUT-not-converting-character-to-numeric/m-p/981227#M379050</guid>
      <dc:creator>hubernomiddle</dc:creator>
      <dc:date>2025-12-22T19:39:52Z</dc:date>
    </item>
    <item>
      <title>Re: INPUT not converting character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INPUT-not-converting-character-to-numeric/m-p/981236#M379051</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/280176"&gt;@hubernomiddle&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Also just a side question, I left in a COL2 that when PROC IMPORT'ed, 0.07 gets converted to "7.0000000000000007E-2". I assume this is just floating point but not sure why this happens if it's being read as character.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The reason is that the numeric value is given as&lt;/P&gt;
&lt;PRE&gt;&amp;lt;v&amp;gt;7.0000000000000007E-2&amp;lt;/v&amp;gt;&lt;/PRE&gt;
&lt;P&gt;in the XML code which (in zipped form) is contained in your .xlsx file. I see also&lt;/P&gt;
&lt;PRE&gt;&amp;lt;v&amp;gt;2.0099999999999998&amp;lt;/v&amp;gt;&lt;/PRE&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;PRE&gt;&amp;lt;v&amp;gt;1.1000000000000001&amp;lt;/v&amp;gt;&lt;/PRE&gt;
&lt;P&gt;in there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In all three cases the small deviations from 0.07, 2.01 and 1.1, respectively, just reflect the unavoidable rounding errors of the binary floating-point representations of 0.07, 2.01 and 1.1 with 52 mantissa bits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If those values are read as &lt;EM&gt;numeric&lt;/EM&gt; values (using the INPUT statement, the INPUT function or assignment statements with those literals), SAS will regard them exactly equal to&amp;nbsp;0.07, 2.01 and 1.1, respectively, without further rounding -- which you could apply otherwise:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input x;
put x hex16.;
cards;
7.0000000000000007E-2
0.07
2.0099999999999998
2.01
1.1000000000000001
1.1  
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;3FB1EB851EB851EC
3FB1EB851EB851EC
4000147AE147AE14
4000147AE147AE14
3FF199999999999A
3FF199999999999A
&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Dec 2025 09:55:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INPUT-not-converting-character-to-numeric/m-p/981236#M379051</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2025-12-23T09:55:13Z</dc:date>
    </item>
  </channel>
</rss>

