05-15-2018 02:35 AM
Hello, I want to convert character to numeric.
My data looks like this :
I tried to use input
Price_new = input(Price, best12.2);
But the result I get as follows:
As you can see the problem is when the number is without decimal point. Please help me.
05-15-2018 05:43 AM - edited 05-15-2018 08:28 AM
When you specify decimals in an informat (as in your input function), you force SAS to convert as many digits to decimals when no decimal point is found in the string. You only specify decimals in an informat when you need to do that conversion yourself (eg when you receive decimal fixed data from mainframes).
Edited because decimal point in instring overrides format definition.
05-15-2018 08:22 AM
SAS is just doing what you asked it to do. The decimal part of an INFORMAT tells SAS where to place the decimal point when the text string doesn't have one. It is for reading data that has been written without the decimal point on purpose to save space in the text file.
Just use an informat of 32.. Or even better use COMMA32. as it will handle strings that include commas and dollar signs.