10-11-2012 01:49 AM
i had a character variable with the following values...
while converting it to numeric variable, the trailing zeros are disappeared...is there any way to retain the exact decimal numbers while converting from character to numeric variable...
10-11-2012 07:22 AM
SAS stores numbers as floating point, so there is no difference in how it is stored between the numbers 1.0 and 1.0000 in your example input stream. You can use a FORMAT to tell SAS how to display the number, but the same format will be applied to every observation in the data. For your example data you could use the format 6.4 (which can also be written as F6.4).
input char $ @@;
num = input(char,6.4);
put char= num= num= 6.4 ;
1.0 2.123 1.222 1.0000 3.1022
char=1.0 num=1 num=1.0000
char=2.123 num=2.123 num=2.1230
char=1.222 num=1.222 num=1.2220
char=1.0000 num=1 num=1.0000
char=3.1022 num=3.1022 num=3.1022
10-11-2012 05:19 PM
To follow-on what data_null_ stated ("What you do with that information is up to you.") I think it would be helpful to describe why you want to do this. It would seem that if you need it both numeric and character, then you keep both variables and use the one that's needed at the time.
For example if the objective is to line up the decimal places so that you get something like
Then you would need to create an additional character string with a fixed length and the decimal would always show in the same position of the character string.
10-11-2012 08:53 AM
You can count the number of decimals in the character string. What you do with that information is up to you.