I am trying to find out the format and informat to the below. I have a .csv file with contain values like 10,900,900.111111 or 999.999 I use the File Reader to read this .csv file. Default File Reader type of value is 'Character' length '8' I used INPUT to convert to Numeric and TRANWRD to replace 'comma' to 'space' and received 109009 value. Which format and informat should I use to with high accuracy reflect the comma and decimal data. Currently the largest number of displayed digits in Sas table have eight digits and in my .csv file some number have as many as sixteen digits. Thank you,
1 Answers
First a note of caution: 16 digits is the maximum you can represent accurately in 8 byte numerics (the way SAS uses them, anyway), and even some 16 digit numbers are not representable (most of the ones beginning with 9, in IEEE floating point systems, like Linux/Unix or Windows).
That aside; the correct informat to read 10,900,900.111111 is comma17., and you could use a longer one if larger numbers are possible - make sure the 17 is equal to the total text length of the number. Also make sure to use a longer format than default (best12. is default) to display it, as otherwise you'll lose some apparent precision (the number will be fully precise, but it will be displayed less precisely).
data _null_;
x = input('10,900,900.111111',comma17.);
put x= best32.;
run;
If you wanted to remove the commas, you could do that with compress which is sort of like tranwrd (or the more common translate) except it removes things; so you could do nocomma = compress(commastr,','); and it would remove the commas.