I am trying to convert a character variable containing a number into a numeric variable without losing decimal precision. Here is an example with output:
data _null_;
format res 20.17;
res = input("54.78566360473633",20.17);
put res;
run;
and the result:
54.78566360473630000
You can see that the number of digits in the result is correct, but the last non-zero digit does not match the final digit of the character variable. I've tried using formats with a larger and smaller number of digits (such as 18.15 or 15.13), and I've tried "forcing" the number of decimals with a format like f20.17, but none of this seems to be working.
I've tried looking through some documentation pages but nothing seems germane. I'm sure this is really basic stuff I'm missing here but, how can I get sas to faithfully read in all digits?
SAS has two data types. Floating point numbers and fixed length character strings. Formats are just instructions for how to display the value. Informats are instructions for how to convert text into values. Neither the FORMAT attached to a variable or the INFORMAT used to create the values in the variable have any impact on how the number is stored.
If you want to use decimal arithmetic then store your values as integers and keep track of the exponent in a separate variable. But even then you will be limited in the precision you can store based on the size of the mantissa used in the floating point representation used by your version of SAS. You can see the largest contiguous integer that SAS can store exactly using the EXACTINT option of the CONSTANT() function.