<?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 Convert CHAR to NUMERIC in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Convert-CHAR-to-NUMERIC/m-p/73637#M21350</link>
    <description>Hello everyone,&lt;BR /&gt;
&lt;BR /&gt;
I am using INPUT( ) to convert a character column to numeric.  But it's not working as I expected.  &lt;BR /&gt;
&lt;BR /&gt;
second_prin_bal = input(first_pirn_bal2, ??8.);&lt;BR /&gt;
&lt;BR /&gt;
a few examples: &lt;BR /&gt;
&lt;BR /&gt;
first_prin_bal2: NULL  second_prin_bal: .&lt;BR /&gt;
first_prin_bal2: 19,856  second_prin_bal: .&lt;BR /&gt;
first_prin_bal2: NULL  second_prin_bal: .&lt;BR /&gt;
first_prin_bal2: NULL  second_prin_bal: .&lt;BR /&gt;
first_prin_bal2: 74,246  second_prin_bal: .&lt;BR /&gt;
first_prin_bal2: NULL  second_prin_bal: .&lt;BR /&gt;
&lt;BR /&gt;
How can I convert this properly?&lt;BR /&gt;
Thanks in advance for any input!</description>
    <pubDate>Tue, 06 Apr 2010 14:14:13 GMT</pubDate>
    <dc:creator>KevinC_</dc:creator>
    <dc:date>2010-04-06T14:14:13Z</dc:date>
    <item>
      <title>Convert CHAR to NUMERIC</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-CHAR-to-NUMERIC/m-p/73637#M21350</link>
      <description>Hello everyone,&lt;BR /&gt;
&lt;BR /&gt;
I am using INPUT( ) to convert a character column to numeric.  But it's not working as I expected.  &lt;BR /&gt;
&lt;BR /&gt;
second_prin_bal = input(first_pirn_bal2, ??8.);&lt;BR /&gt;
&lt;BR /&gt;
a few examples: &lt;BR /&gt;
&lt;BR /&gt;
first_prin_bal2: NULL  second_prin_bal: .&lt;BR /&gt;
first_prin_bal2: 19,856  second_prin_bal: .&lt;BR /&gt;
first_prin_bal2: NULL  second_prin_bal: .&lt;BR /&gt;
first_prin_bal2: NULL  second_prin_bal: .&lt;BR /&gt;
first_prin_bal2: 74,246  second_prin_bal: .&lt;BR /&gt;
first_prin_bal2: NULL  second_prin_bal: .&lt;BR /&gt;
&lt;BR /&gt;
How can I convert this properly?&lt;BR /&gt;
Thanks in advance for any input!</description>
      <pubDate>Tue, 06 Apr 2010 14:14:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-CHAR-to-NUMERIC/m-p/73637#M21350</guid>
      <dc:creator>KevinC_</dc:creator>
      <dc:date>2010-04-06T14:14:13Z</dc:date>
    </item>
    <item>
      <title>Re: Convert CHAR to NUMERIC</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-CHAR-to-NUMERIC/m-p/73638#M21351</link>
      <description>Use COMMA INFORMAT.</description>
      <pubDate>Tue, 06 Apr 2010 14:37:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-CHAR-to-NUMERIC/m-p/73638#M21351</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-04-06T14:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: Convert CHAR to NUMERIC</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-CHAR-to-NUMERIC/m-p/73639#M21352</link>
      <description>Hi KevinC,&lt;BR /&gt;
&lt;BR /&gt;
You can use the following statement:&lt;BR /&gt;
&lt;BR /&gt;
if input(first_prin_bal2, ?? best.) &amp;gt; .z then second_prin_bal2=first_prin_bal2+0;&lt;BR /&gt;
&lt;BR /&gt;
Kind regards,&lt;BR /&gt;
Florent</description>
      <pubDate>Tue, 06 Apr 2010 14:41:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-CHAR-to-NUMERIC/m-p/73639#M21352</guid>
      <dc:creator>Florent</dc:creator>
      <dc:date>2010-04-06T14:41:19Z</dc:date>
    </item>
    <item>
      <title>Re: Convert CHAR to NUMERIC</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-CHAR-to-NUMERIC/m-p/73640#M21353</link>
      <description>Thank you both for your response!! &lt;BR /&gt;
I played with it and I got it to work using put(xxx,??comma8.); &lt;BR /&gt;
&lt;BR /&gt;
Thanks agian to everyone !</description>
      <pubDate>Tue, 06 Apr 2010 17:43:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-CHAR-to-NUMERIC/m-p/73640#M21353</guid>
      <dc:creator>KevinC_</dc:creator>
      <dc:date>2010-04-06T17:43:12Z</dc:date>
    </item>
    <item>
      <title>Re: Convert CHAR to NUMERIC</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-CHAR-to-NUMERIC/m-p/73641#M21354</link>
      <description>While on the topic, and unrelated to the comma informat, but related to the subject:&lt;BR /&gt;
&lt;BR /&gt;
1- best. in not an official informat&lt;BR /&gt;
2- best. is not even the best informat for reading numbers.&lt;BR /&gt;
3- 32. is the best informat for reading numbers&lt;BR /&gt;
4- 32. still generates erroneous readings for large numbers as only part of the number is read&lt;BR /&gt;
5- Letting sas do the conversion by adding +0 to a string as above is the only fool-proof solution, but generates the infamous message [pre] NOTE: Character values have been converted to numeric values at the places given by:[/pre]6- I reckon sas should provide a to_number() function so all normal (no comma etc) numbers can safely be read with no noxious log message. &lt;BR /&gt;
&lt;BR /&gt;
Code:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  format Y best32.;&lt;BR /&gt;
  input X $40. COMMENT $40.; put COMMENT;&lt;BR /&gt;
  Y=X+0;                 put '0 ' X= Y=;&lt;BR /&gt;
  Y=input(X,?? best32.); put '1 ' X= Y=;&lt;BR /&gt;
  Y=input(X,?? 32.    ); put '2 ' X= Y=;&lt;BR /&gt;
cards;&lt;BR /&gt;
1234567890123456789012345678901234567890           columns (integer &amp;gt;32)&lt;BR /&gt;
123456798012345678901234567980                     integer ≤32&lt;BR /&gt;
1234567980123456789.1234567890123456789            integer part ≤32&lt;BR /&gt;
1234567980123456789012345679801234567.8            integer part &amp;gt;32&lt;BR /&gt;
0.0000000000000000001234567890123456789            small decimal&lt;BR /&gt;
0.0000000000000000000000000000000000012            very small decimal&lt;BR /&gt;
1234567980123456789012345678e10                    positive scientific&lt;BR /&gt;
12345679801234567890123456789012e10                positive scientific length&amp;gt;32&lt;BR /&gt;
1234567980123456789012345678e-10                   negative scientific&lt;BR /&gt;
1234567980123456789012345678901e-10                negative scientific length&amp;gt;32&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Result:&lt;BR /&gt;
[pre]&lt;BR /&gt;
columns (integer &amp;gt;32)&lt;BR /&gt;
0 X=1234567890123456789012345678901234567890 Y=1.2345678901234E39 =&amp;gt; correct&lt;BR /&gt;
1 X=1234567890123456789012345678901234567890 Y=12345678901234566802609541218304 =&amp;gt; incorrect&lt;BR /&gt;
&lt;BR /&gt;
2 X=1234567890123456789012345678901234567890 Y=12345678901234566802609541218304 =&amp;gt; incorrect&lt;BR /&gt;
&lt;BR /&gt;
integer ≤32&lt;BR /&gt;
0 X=123456798012345678901234567980 Y=123456798012345682323755237376 =&amp;gt; correct&lt;BR /&gt;
1 X=123456798012345678901234567980 Y=123456798012345682323755237376 =&amp;gt; correct&lt;BR /&gt;
2 X=123456798012345678901234567980 Y=123456798012345682323755237376 =&amp;gt; correct&lt;BR /&gt;
&lt;BR /&gt;
integer part ≤32&lt;BR /&gt;
0 X=1234567980123456789.1234567890123456789 Y=1234567980123456768 =&amp;gt; correct&lt;BR /&gt;
1 X=1234567980123456789.1234567890123456789 Y=1234567980123456768 =&amp;gt; correct&lt;BR /&gt;
2 X=1234567980123456789.1234567890123456789 Y=1234567980123456768 =&amp;gt; correct&lt;BR /&gt;
&lt;BR /&gt;
integer part &amp;gt;32&lt;BR /&gt;
0 X=1234567980123456789012345679801234567.8 Y=1.2345679801234E36 =&amp;gt; correct&lt;BR /&gt;
1 X=1234567980123456789012345679801234567.8 Y=12345679801234567106475616894976 =&amp;gt; incorrect&lt;BR /&gt;
2 X=1234567980123456789012345679801234567.8 Y=12345679801234567106475616894976 =&amp;gt; incorrect&lt;BR /&gt;
&lt;BR /&gt;
small decimal&lt;BR /&gt;
0 X=0.0000000000000000001234567890123456789 Y=1.2345678901234E-19 =&amp;gt; more precision&lt;BR /&gt;
1 X=0.0000000000000000001234567890123456789 Y=1.23456789012E-19 =&amp;gt; less precision&lt;BR /&gt;
2 X=0.0000000000000000001234567890123456789 Y=1.23456789012E-19 =&amp;gt; less precision&lt;BR /&gt;
&lt;BR /&gt;
very small decimal&lt;BR /&gt;
0 X=0.0000000000000000000000000000000000012 Y=1.2E-36 =&amp;gt; correct&lt;BR /&gt;
1 X=0.0000000000000000000000000000000000012 Y=0 =&amp;gt; incorrect&lt;BR /&gt;
2 X=0.0000000000000000000000000000000000012 Y=0 =&amp;gt; incorrect&lt;BR /&gt;
&lt;BR /&gt;
positive scientific&lt;BR /&gt;
0 X=1234567980123456789012345678e10 Y=1.2345679801234E37 =&amp;gt; correct&lt;BR /&gt;
1 X=1234567980123456789012345678e10 Y=1.2345679801234E37 =&amp;gt; correct&lt;BR /&gt;
2 X=1234567980123456789012345678e10 Y=1.2345679801234E37 =&amp;gt; correct&lt;BR /&gt;
&lt;BR /&gt;
positive scientific length&amp;gt;32&lt;BR /&gt;
0 X=12345679801234567890123456789012e10 Y=1.2345679801234E41 =&amp;gt; correct&lt;BR /&gt;
1 X=12345679801234567890123456789012e10 Y=12345679801234567106475616894976 =&amp;gt; incorrect&lt;BR /&gt;
2 X=12345679801234567890123456789012e10 Y=12345679801234567106475616894976 =&amp;gt; incorrect&lt;BR /&gt;
&lt;BR /&gt;
negative scientific&lt;BR /&gt;
0 X=1234567980123456789012345678e-10 Y=123456798012345680 =&amp;gt; correct&lt;BR /&gt;
1 X=1234567980123456789012345678e-10 Y=123456798012345680 =&amp;gt; correct&lt;BR /&gt;
2 X=1234567980123456789012345678e-10 Y=123456798012345680 =&amp;gt; correct&lt;BR /&gt;
&lt;BR /&gt;
negative scientific length&amp;gt;32&lt;BR /&gt;
0 X=1234567980123456789012345678901e-10 Y=123456798012345679872 =&amp;gt; correct&lt;BR /&gt;
1 X=1234567980123456789012345678901e-10 Y=. =&amp;gt; incorrect&lt;BR /&gt;
2 X=1234567980123456789012345678901e-10 Y=. =&amp;gt; incorrect&lt;BR /&gt;
&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 07 Apr 2010 03:45:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-CHAR-to-NUMERIC/m-p/73641#M21354</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2010-04-07T03:45:16Z</dc:date>
    </item>
  </channel>
</rss>

