```Date: Wed, 24 May 2006 11:17:16 -0400 Reply-To: Gerhard Hellriegel Sender: "SAS(r) Discussion" From: Gerhard Hellriegel Subject: Re: Best. informat in input function? If you values only have variations like you described, you don't need the BEST. informat. Also 10. (long enough) would do. Yes, several problems lurking around the corner, because not all chars are valid numerics (the other way is easier). E.g. look at the exotic string: 31 data test; 32 a="11.5d-13"; 33 x=input(a,10.); 34 put _all_; 35 run; a=11.5d-13 x=1.15E-12 _ERROR_=0 _N_=1 Then look at the less exotic string: 46 data test; 47 a="1 13"; 48 x=input(a,10.); 49 put _all_; 50 run; NOTE: Invalid argument to function INPUT at line 48 column 5. a=1 13 x=. _ERROR_=1 _N_=1 a=1 13 x=. _ERROR_=1 _N_=1 where 71 data test; 72 a="1.e13"; 73 x=input(a,10.); 74 put _all_; 75 run; a=1.e13 x=1E13 _ERROR_=0 _N_=1 is ok! Some chars are allowed, some not, some only at certain positions or in certain combinations. E.g. "+" and "-"! Allowed, but only one of them - really? 76 data test; 77 a="-1.e-13"; 78 x=input(a,10.); 79 put _all_; 80 run; a=-1.e-13 x=-1E-13 _ERROR_=0 _N_=1 but 81 data test; 82 a="-1.-13"; 83 x=input(a,10.); 84 put _all_; 85 run; NOTE: Invalid argument to function INPUT at line 83 column 5. a=-1.-13 x=. _ERROR_=1 _N_=1 a=-1.-13 x=. _ERROR_=1 _N_=1 So you see: you could check, if the string is numeric or not, but it is not easy! And the informat, if BEST10. or 10. is not too important, but don't use 10.2: 106 data test; 107 a="11.345"; 108 x=input(a,10.2); 109 put _all_; 110 a="11345"; 111 x=input(a,10.2); 112 put _all_; 113 run; a=11.345 x=11.345 _ERROR_=0 _N_=1 a=11345 x=113.45 _ERROR_=0 _N_=1 The first might be what you expected, but the second? On Wed, 24 May 2006 10:50:10 -0400, David Ryerson wrote: >Hello, > >I am trying to convert a character variable to a numeric variable with the >input function. The twist is that the values of the character variable >vary quite a bit in terms of no decimal, one digit after decimal, etc. I >have been using the following to do this: > >numval=input(charval,best.); > >Is the best. informat the way to go here? To this point it seems to be >working, but I'm wondering if there are any problems lurking around the >corner. > >Thanks, >David ```

Back to: Top of message | Previous page | Main SAS-L page