## converting character values to numeric values

Solved
Frequent Contributor
Posts: 82

# converting character values to numeric values

Hello,

May you help with following converting the characer value with decimal into numeric value:

test = input( price, best12.) , it did not work.

Price:  Format \$7, informat \$7.

example of price :  6.32,  0.11,  0.44, 11.73

Thank you.

Ivy

Accepted Solutions
Solution
‎03-29-2017 09:25 PM
PROC Star
Posts: 8,164

## Re: converting character values to numeric values

Works for me. I'd have to think that you entered something wrong (e.g., missing semi-colon or the like).

The following works:

```data have;
format  price \$7.;
informat price \$7.;
input price;
cards;
6.32
0.11
0.44
11.73
;

data want;
set have;
test = input( price, best12.);
run;
```

Art, CEO, AnalystFinder.com

All Replies
Solution
‎03-29-2017 09:25 PM
PROC Star
Posts: 8,164

## Re: converting character values to numeric values

Works for me. I'd have to think that you entered something wrong (e.g., missing semi-colon or the like).

The following works:

```data have;
format  price \$7.;
informat price \$7.;
input price;
cards;
6.32
0.11
0.44
11.73
;

data want;
set have;
test = input( price, best12.);
run;
```

Art, CEO, AnalystFinder.com

Frequent Contributor
Posts: 82

## Re: converting character values to numeric values

Thank you , the special non-printing character in the column made that did not work.
Super User
Posts: 8,089

## Re: converting character values to numeric values

Your example statement should work.  Make sure that your text string does not have non-printing characters like tabs, carriage returns or non-breaking spaces ('09'x,'0A'x,'A0'x, respectively).

``````data want ;
length price \$7 ;
input price ;
test = input(price, 7.);
cards;
6.32
0.11
0.44
11.73
;;;;``````

A couple of notes.

• The LENGTH of a character variable is more important than what FORMAT or INFORMAT is attached to it.  In fact the FORMAT can actually cause trouble if it doesn't match the length since it can make it hard to debug.
• BEST is really a FORMAT and not an INFORMAT.  SAS will just use the 12. INFORMAT if you ask it to use BEST12. as in informat. Actually for reading text into numbers the COMMA informat is good one to use because it will ignore dollar signs and commas in your strings.

To see if your strings have non-printing characters print the value using \$HEX format. '20'X is the code for a space.

Or you the COMPRESS() function to remove non digits.  Something like this might help.

``test = input(COMPRESS(price, "+.-", "d"),32.);``

Frequent Contributor
Posts: 82

## Re: converting character values to numeric values

Thank you very much. There is special character in the column which made it did not work.
Super User
Posts: 13,523

## Re: converting character values to numeric values

Doesn't work is awful vague.

Are there errors in the log: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.

Unexpected output? Provide input data in the form of a dataset, the actual results and the expected results. Data should be in the form of a data step. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

Also is your value for Price= '6.32' or '\$6.32'? or does your Price have values separated by commas? Leading spaces? It isn't quite clear from your example.

Frequent Contributor
Posts: 82

## Re: converting character values to numeric values

Thank you !
☑ This topic is solved.