<?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: Error converting character to value to numeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Error-converting-character-to-value-to-numeric/m-p/941543#M369385</link>
    <description>Thank you. Problem solved.</description>
    <pubDate>Wed, 28 Aug 2024 18:57:39 GMT</pubDate>
    <dc:creator>joesmama</dc:creator>
    <dc:date>2024-08-28T18:57:39Z</dc:date>
    <item>
      <title>Error converting character to value to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-converting-character-to-value-to-numeric/m-p/941529#M369371</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;I am reading in an Excel spreadsheet and need to convert a character variable to a numeric one.&amp;nbsp; I'm trying to create a new variable using the INPUT command&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Days_to_Event=input(Days_to_Event_A, 8..);&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but I keep getting this error:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: Invalid argument to function INPUT at line 480 column 20&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Most of the converted data is missing. What am I missing here?&amp;nbsp;Is it possible that&amp;nbsp; for the variable in question in the Excel spreadsheet that some of the values are character and some numeric? I need help moving forward.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All help is appreciated.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 17:44:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-converting-character-to-value-to-numeric/m-p/941529#M369371</guid>
      <dc:creator>joesmama</dc:creator>
      <dc:date>2024-08-28T17:44:25Z</dc:date>
    </item>
    <item>
      <title>Re: Error converting character to value to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-converting-character-to-value-to-numeric/m-p/941530#M369372</link>
      <description>&lt;P&gt;Maxim 3: Know Your Data.&lt;/P&gt;
&lt;P&gt;What strings are contained in your variable? Do they constitute valid (for the informat used) numbers?&lt;/P&gt;
&lt;P&gt;Which means they contain only digits, maybe a decimal dot, and a leading sign.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If in doubt, post examples here into a window opened with this button:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54552i914D97BE1B0F21E5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 17:47:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-converting-character-to-value-to-numeric/m-p/941530#M369372</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-08-28T17:47:07Z</dc:date>
    </item>
    <item>
      <title>Re: Error converting character to value to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-converting-character-to-value-to-numeric/m-p/941531#M369373</link>
      <description>&lt;P&gt;Run Proc Contents on your data set and share the results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, it is best practice to copy from the &lt;STRONG&gt;log&lt;/STRONG&gt; the entire data step or procedure along with all the note, messages, warnings or errors. Then on the forum open a text box using the &amp;lt;/&amp;gt; icon above the message window and paste all the copied text. The text box is important because the forum software will reformat text pasted into the main message window which reduces the usefulness of diagnostic characters SAS often supplies. Also the entire data step or procedure is important because many issues can relate to problems caused on previous lines such as missing semicolons, mismatched quotes or parentheses. And when SAS says "column 20" we can tell which is column 20.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And the complete log likely shows enough information, such as the extremely likely not valid to create a number using the 8. informat in the log as well. Example:&lt;/P&gt;
&lt;PRE&gt;153  data junk;
154    dta='not a number';
155    days=input(dta,8.);
156  run;

NOTE: Invalid argument to function INPUT at line 155 column 8.
dta=not a number days=. _ERROR_=1 _N_=1
NOTE: Mathematical operations could not be performed at the following places. The results of the
      operations have been set to missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      1 at 155:8
NOTE: The data set USER.JUNK has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds

&lt;/PRE&gt;
&lt;P&gt;I strongly suspect that some values of Days_to_Event_A either have text like "missing" "NA" or the number with something else like "7 days". None of those can be read with a&amp;nbsp; W. informat and would require example values and possibly expected results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 17:52:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-converting-character-to-value-to-numeric/m-p/941531#M369373</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-08-28T17:52:53Z</dc:date>
    </item>
    <item>
      <title>Re: Error converting character to value to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-converting-character-to-value-to-numeric/m-p/941532#M369374</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Days_to_Event=input(Days_to_Event_A, 8..); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are two dots after the number 8, that is an error. But the error message you are getting about invalid input means your variable Days_to_Event_A is the wrong type, for INPUT to work it must be character (and obviously it is not character).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And yes, next time show us the log for a DATA step or PROC, showing us the code that appears in the log plus all warnings, errors and notes for the PROC or DATA step with the error, pasted in to the text box that appears when you click on the &amp;lt;/&amp;gt; icon, as described by the others.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 17:51:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-converting-character-to-value-to-numeric/m-p/941532#M369374</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-08-28T17:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: Error converting character to value to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-converting-character-to-value-to-numeric/m-p/941538#M369383</link>
      <description>&lt;P&gt;Why are you telling INPUT to only use the first 8 bytes of the character variable?&amp;nbsp; Remember the INPUT function does not care if the WIDTH used on the informat is larger than the LENGTH of the string you gave it to read.&amp;nbsp; So use the maximum width the informat allows.&amp;nbsp; Which is 32.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the column in your EXCEL file has a mix of numeric and character cells then SAS will make the variable CHARACTER.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If SAS is not already printing the values that did not convert then you can add your own code to test and display them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Days_to_Event=input(Days_to_Event_A, ??32.); 
if missing(Days_to_Event) and not missing(Days_to_Event_A) then 
  put 'NOTE: ' _n_= Days_to_Event_A= :$quote. 'could not be converted to a number.' 
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 18:21:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-converting-character-to-value-to-numeric/m-p/941538#M369383</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-08-28T18:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: Error converting character to value to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-converting-character-to-value-to-numeric/m-p/941543#M369385</link>
      <description>Thank you. Problem solved.</description>
      <pubDate>Wed, 28 Aug 2024 18:57:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-converting-character-to-value-to-numeric/m-p/941543#M369385</guid>
      <dc:creator>joesmama</dc:creator>
      <dc:date>2024-08-28T18:57:39Z</dc:date>
    </item>
  </channel>
</rss>

