<?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: Character to Numeric conversion issues in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric-conversion-issues/m-p/437717#M109043</link>
    <description>&lt;P&gt;Try using the BEST32 informat instead and let SAS make a guess. I suspect it may do a better job.&lt;/P&gt;
&lt;P&gt;Note that when you specify a informat of 24.2 it expects all values to have two decimal places, so 100 becomes 1.00&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/29074"&gt;@Ody&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi folks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have mixed numeric data formatted as character. The data values range from the single digits into the billions. Some of the data is null or missing, some has decimal places, some of the numeric characters have commas, etc...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm having a really hard time converting these values to numeric with the correct format. I've tried almost all the numeric formats I can think of within an input statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As an example:&lt;/P&gt;
&lt;P&gt;value1a = input(value1,24.2);&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;value1a =&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;input(value1&lt;/SPAN&gt;&lt;SPAN&gt;,comma24.2);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;value1a =&amp;nbsp;input(value1,??24.2);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;value1a =&amp;nbsp;input(value1,??24.);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some of these formats don't produce results for very large numbers, some don't produce results at all. The closest I've gotten was using&amp;nbsp;&lt;SPAN&gt;input(value1&lt;/SPAN&gt;&lt;SPAN&gt;,??24.) but this is adding decimals to all the values turing a value like 1280 into 12.80.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Any thoughts on this?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="font-weight: 400;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data&amp;nbsp;test;

infile&amp;nbsp;datalines&amp;nbsp;dsd&amp;nbsp;truncover;

input

value1:$200.

value2:$200.

value3:$200.

value4:$200.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;

;

&amp;nbsp;

datalines;

'1001322', '48,371,804.50', '91662', '2,295,968.99'

'1280', '73,393.39', '143, 3,656.94'

'2', 222, , '59888.99'

'255287', '22,401,559.53', '5432618', '210,129,208.53'

'735034', '34,031,056.78', '89640',

'1992923', '104,877,814.20', '5614063', '1,214,793,943.92'

;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Feb 2018 18:29:59 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-02-15T18:29:59Z</dc:date>
    <item>
      <title>Character to Numeric conversion issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric-conversion-issues/m-p/437716#M109042</link>
      <description>&lt;P&gt;Hi folks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have mixed numeric data formatted as character. The data values range from the single digits into the billions. Some of the data is null or missing, some has decimal places, some of the numeric characters have commas, etc...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm having a really hard time converting these values to numeric with the correct format. I've tried almost all the numeric formats I can think of within an input statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As an example:&lt;/P&gt;
&lt;P&gt;value1a = input(value1,24.2);&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;value1a =&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;input(value1&lt;/SPAN&gt;&lt;SPAN&gt;,comma24.2);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;value1a =&amp;nbsp;input(value1,??24.2);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;value1a =&amp;nbsp;input(value1,??24.);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some of these formats don't produce results for very large numbers, some don't produce results at all. The closest I've gotten was using&amp;nbsp;&lt;SPAN&gt;input(value1&lt;/SPAN&gt;&lt;SPAN&gt;,??24.) but this is adding decimals to all the values turing a value like 1280 into 12.80.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Any thoughts on this?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="font-weight: 400;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data&amp;nbsp;test;

infile&amp;nbsp;datalines&amp;nbsp;dsd&amp;nbsp;truncover;

input

value1:$200.

value2:$200.

value3:$200.

value4:$200.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;

;

&amp;nbsp;

datalines;

'1001322', '48,371,804.50', '91662', '2,295,968.99'

'1280', '73,393.39', '143, 3,656.94'

'2', 222, , '59888.99'

'255287', '22,401,559.53', '5432618', '210,129,208.53'

'735034', '34,031,056.78', '89640',

'1992923', '104,877,814.20', '5614063', '1,214,793,943.92'

;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 18:27:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric-conversion-issues/m-p/437716#M109042</guid>
      <dc:creator>Ody</dc:creator>
      <dc:date>2018-02-15T18:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric conversion issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric-conversion-issues/m-p/437717#M109043</link>
      <description>&lt;P&gt;Try using the BEST32 informat instead and let SAS make a guess. I suspect it may do a better job.&lt;/P&gt;
&lt;P&gt;Note that when you specify a informat of 24.2 it expects all values to have two decimal places, so 100 becomes 1.00&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/29074"&gt;@Ody&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi folks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have mixed numeric data formatted as character. The data values range from the single digits into the billions. Some of the data is null or missing, some has decimal places, some of the numeric characters have commas, etc...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm having a really hard time converting these values to numeric with the correct format. I've tried almost all the numeric formats I can think of within an input statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As an example:&lt;/P&gt;
&lt;P&gt;value1a = input(value1,24.2);&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;value1a =&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;input(value1&lt;/SPAN&gt;&lt;SPAN&gt;,comma24.2);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;value1a =&amp;nbsp;input(value1,??24.2);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;value1a =&amp;nbsp;input(value1,??24.);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some of these formats don't produce results for very large numbers, some don't produce results at all. The closest I've gotten was using&amp;nbsp;&lt;SPAN&gt;input(value1&lt;/SPAN&gt;&lt;SPAN&gt;,??24.) but this is adding decimals to all the values turing a value like 1280 into 12.80.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Any thoughts on this?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="font-weight: 400;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data&amp;nbsp;test;

infile&amp;nbsp;datalines&amp;nbsp;dsd&amp;nbsp;truncover;

input

value1:$200.

value2:$200.

value3:$200.

value4:$200.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;

;

&amp;nbsp;

datalines;

'1001322', '48,371,804.50', '91662', '2,295,968.99'

'1280', '73,393.39', '143, 3,656.94'

'2', 222, , '59888.99'

'255287', '22,401,559.53', '5432618', '210,129,208.53'

'735034', '34,031,056.78', '89640',

'1992923', '104,877,814.20', '5614063', '1,214,793,943.92'

;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 18:29:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric-conversion-issues/m-p/437717#M109043</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-15T18:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric conversion issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric-conversion-issues/m-p/437727#M109052</link>
      <description>&lt;P&gt;Thanks for the feedback.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried using best32. and while some of the data converted accurately much of it did not.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I seem to be running into an issue where data is missing or the numbers are large with decimals or commas.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any other suggestions?&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 19:01:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric-conversion-issues/m-p/437727#M109052</guid>
      <dc:creator>Ody</dc:creator>
      <dc:date>2018-02-15T19:01:36Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric conversion issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric-conversion-issues/m-p/437731#M109054</link>
      <description>&lt;P&gt;Try the comma24. informat.&amp;nbsp; The ?? is optional.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 19:25:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric-conversion-issues/m-p/437731#M109054</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-15T19:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric conversion issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric-conversion-issues/m-p/437735#M109056</link>
      <description>&lt;P&gt;Thanks for the reply,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The format comma24. doesn't seem to work either. I tried that earlier just didnt list it as one of the option I tried.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a copy of my log using the best32. format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Appreciate any insight into this. Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data test1;
set test;

value1a = input(value1,best32.);
value2a = input(value2,best32.);
value3a = input(value3,best32.);
value4a = input(value4,best32.);

run;


479  data test1;
480  set test;
481
482  value1a = input(value1,best32.);
483  value2a = input(value2,best32.);
484  value3a = input(value3,best32.);
485  value4a = input(value4,best32.);
486
487  run;

NOTE: Invalid argument to function INPUT at line 483 column 11.
NOTE: Invalid argument to function INPUT at line 485 column 11.
value1=1001322 value2=48,371,804.50 value3=91662 value4=2,295,968.99 value1a=1001322 value2a=.
value3a=91662 value4a=. _ERROR_=1 _N_=1
NOTE: Invalid argument to function INPUT at line 483 column 11.
NOTE: Invalid argument to function INPUT at line 484 column 11.
value1=1280 value2=73,393.39 value3=143, 3,656.94 value4=  value1a=1280 value2a=. value3a=.
value4a=. _ERROR_=1 _N_=2
NOTE: Invalid argument to function INPUT at line 483 column 11.
NOTE: Invalid argument to function INPUT at line 485 column 11.
value1=255287 value2=22,401,559.53 value3=5432618 value4=210,129,208.53 value1a=255287
value2a=. value3a=5432618 value4a=. _ERROR_=1 _N_=4
NOTE: Invalid argument to function INPUT at line 483 column 11.
value1=735034 value2=34,031,056.78 value3=89640 value4=  value1a=735034 value2a=. value3a=89640
value4a=. _ERROR_=1 _N_=5
NOTE: Invalid argument to function INPUT at line 483 column 11.
NOTE: Invalid argument to function INPUT at line 485 column 11.
value1=1992923 value2=104,877,814.20 value3=5614063 value4=214,793,943.92 value1a=1992923
value2a=. value3a=5614063 value4a=. _ERROR_=1 _N_=6
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).
      5 at 483:11   1 at 484:11   3 at 485:11
NOTE: There were 6 observations read from the data set WORK.TEST.
NOTE: The data set WORK.TEST1 has 6 observations and 8 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.00 seconds


NOTE: Remote submit to EMSVR complete.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Feb 2018 19:37:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric-conversion-issues/m-p/437735#M109056</guid>
      <dc:creator>Ody</dc:creator>
      <dc:date>2018-02-15T19:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric conversion issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric-conversion-issues/m-p/437741#M109059</link>
      <description>&lt;P&gt;It looks like some of the data was read in incorrectly (previously).&amp;nbsp; For example, it looks like on observation 2, VALUE3 should be 143 and VALUE4 should be 3,656.94.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once that is cleared up, the comma24. informat should work just fine.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 19:47:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric-conversion-issues/m-p/437741#M109059</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-15T19:47:07Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric conversion issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric-conversion-issues/m-p/437742#M109060</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;

infile datalines dsd truncover;

input

value1:$200.

value2:$200.

value3:$200.

value4:$200.     

;

 

datalines;
'1001322', '48,371,804.50', '91662', '2,295,968.99'
'1280', '73,393.39', '143, 3,656.94'
'2', 222, , '59888.99'
'255287', '22,401,559.53', '5432618', '210,129,208.53'
'735034', '34,031,056.78', '89640',
'1992923', '104,877,814.20', '5614063', '1,214,793,943.92'
;;;


data want;
set test;
v1=input(value1,comma32.);
v2=input(value2,comma32.);
v3=input(value3,comma32.);
v4=input(value4,comma32.);
run;

 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Feb 2018 19:52:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric-conversion-issues/m-p/437742#M109060</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-02-15T19:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric conversion issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric-conversion-issues/m-p/437743#M109061</link>
      <description>&lt;P&gt;You're correct. I forget a few single quotes when supplying my test data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've changed that and reran the code using both comma24. and comma32. as a format. The results are what I would expect, which is good. This seems to have solved my problem, thanks. Not really sure why when I tried that format earlier I was having issues.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any way, thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 19:56:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric-conversion-issues/m-p/437743#M109061</guid>
      <dc:creator>Ody</dc:creator>
      <dc:date>2018-02-15T19:56:01Z</dc:date>
    </item>
  </channel>
</rss>

