<?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: Cannot convert character to numeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Cannot-convert-character-to-numeric/m-p/784405#M250321</link>
    <description>&lt;P&gt;I've done some more trouble shooting and I guess I should add more details. The code is not working on a transposed dataset. the original data set looks like this&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;data have;
infile datalines;
input SEQNO F001 F002 $ F003 $  F004 $ ;
datalines;
1 2 3 text ...
2 3 4 . ...
3 4 5 . ... 
2 5 6 . ...
;&lt;/LI-CODE&gt;&lt;P&gt;I transpose it by using the following&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;proc transpose data=work.have;
  out=work.have
  prefix=V
  name=Source
  label=Label;
  by SEQNO;
  var &amp;amp;f_name;
RUN;
quit;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After the transpose I get the table I originally provided and the code does not work anymore.&lt;/P&gt;&lt;P&gt;Any additional insights?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Dec 2021 21:29:50 GMT</pubDate>
    <dc:creator>katvit</dc:creator>
    <dc:date>2021-12-06T21:29:50Z</dc:date>
    <item>
      <title>Cannot convert character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-convert-character-to-numeric/m-p/784384#M250305</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input SEQNO Source $ V1 $15.;&lt;BR /&gt;datalines;&lt;BR /&gt;2&amp;nbsp; F008 10&lt;/P&gt;&lt;P&gt;2 F008 15&lt;BR /&gt;2 F008 20&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2 F194 .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to convert V1 from character to numeric.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following code does not work&lt;/P&gt;&lt;P&gt;DATA WORK.want (keep=FD_SEQ FD_YEAR FD_QNUM FD_VALUE);&lt;BR /&gt;SET WORK.have;&lt;BR /&gt;FD_SEQ = SEQNO;&lt;BR /&gt;FD_YEAR = 2019;&lt;BR /&gt;FD_QNUM = LOWCASE(Source);&lt;BR /&gt;FD_VALUE = input(V1, ??30.);&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What am I doing wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 20:26:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-convert-character-to-numeric/m-p/784384#M250305</guid>
      <dc:creator>katvit</dc:creator>
      <dc:date>2021-12-06T20:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot convert character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-convert-character-to-numeric/m-p/784391#M250309</link>
      <description>&lt;P&gt;Your code works fine for me.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines;
input SEQNO Source $ V1 $15.;
datalines;
2  F008 10
2 F008 15
2 F008 20
2 F194 .
;

data want;
  SET have;
  FD_SEQ = SEQNO;
  FD_YEAR = 2019;
  FD_QNUM = LOWCASE(Source);
  FD_VALUE = input(V1, ??30.);
RUN;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    SEQNO    Source    V1    FD_SEQ    FD_YEAR    FD_QNUM    FD_VALUE

 1       2       F008     10       2        2019      f008         10
 2       2       F008     15       2        2019      f008         15
 3       2       F008     20       2        2019      f008         20
 4       2       F194              2        2019      f194          .

&lt;/PRE&gt;
&lt;P&gt;Show the lines from the SAS log for the data step.&amp;nbsp; Make sure to use the Insert Code button (looks like &amp;lt; / &amp;gt; ) to get a pop-up window where you can paste/edit the lines of text you copy from the SAS log.&lt;/P&gt;
&lt;P&gt;Remove the ?? modifier to get SAS to spit out notes/errors when the value of V1 is not able to be converted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also make sure the character strings are in the first 30 bytes of the V1 values.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 20:39:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-convert-character-to-numeric/m-p/784391#M250309</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-06T20:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot convert character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-convert-character-to-numeric/m-p/784405#M250321</link>
      <description>&lt;P&gt;I've done some more trouble shooting and I guess I should add more details. The code is not working on a transposed dataset. the original data set looks like this&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;data have;
infile datalines;
input SEQNO F001 F002 $ F003 $  F004 $ ;
datalines;
1 2 3 text ...
2 3 4 . ...
3 4 5 . ... 
2 5 6 . ...
;&lt;/LI-CODE&gt;&lt;P&gt;I transpose it by using the following&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;proc transpose data=work.have;
  out=work.have
  prefix=V
  name=Source
  label=Label;
  by SEQNO;
  var &amp;amp;f_name;
RUN;
quit;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After the transpose I get the table I originally provided and the code does not work anymore.&lt;/P&gt;&lt;P&gt;Any additional insights?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 21:29:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-convert-character-to-numeric/m-p/784405#M250321</guid>
      <dc:creator>katvit</dc:creator>
      <dc:date>2021-12-06T21:29:50Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot convert character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-convert-character-to-numeric/m-p/784406#M250322</link>
      <description>You may have leading or trailing spaces somewhere. Make sure to apply a TRIM to your variable before using INPUT.</description>
      <pubDate>Mon, 06 Dec 2021 21:44:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-convert-character-to-numeric/m-p/784406#M250322</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-06T21:44:33Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot convert character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-convert-character-to-numeric/m-p/784407#M250323</link>
      <description>&lt;P&gt;If you transpose character and numeric variables then the resulting variable(s) will be character.&amp;nbsp; The numeric values will be converted to text and RIGHT aligned.&amp;nbsp; You should be able to see this if you look at the data directly or print it to plain old text output.&amp;nbsp; But if you look at it with ODS output the leading spaces will be hidden from you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Remove the leading spaces.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;number=input(left(character),32.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Dec 2021 21:51:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-convert-character-to-numeric/m-p/784407#M250323</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-06T21:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot convert character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-convert-character-to-numeric/m-p/784411#M250325</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 22:21:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-convert-character-to-numeric/m-p/784411#M250325</guid>
      <dc:creator>katvit</dc:creator>
      <dc:date>2021-12-06T22:21:39Z</dc:date>
    </item>
  </channel>
</rss>

