Solved
New Contributor
Posts: 4

Help to convert number to character format in scientific notation

Hi all. Looking for the most efficient way to convert a number into character format, but specifically in scientific notation. The specific situation is that I am creating summary tables where my numerical results are converted to character columns rounded to two decimal places. Where key results are < .004 they convert to .00 which is not very informative for the reader (think of log scale parameters in something like regression, which can be large and highly significant at very low values). So, instead of .00** or the like I want something more like 2e-5**. Any ideas? I was thinking about an exploratory do until loop to establish number of decimals and the value, but is there a more efficient way?

Regards

Greg

Accepted Solutions
Solution
‎07-31-2014 08:19 AM
Super Contributor
Posts: 644

Re: Help to convert number to character format in scientific notation

43         data have ;

44         length y \$4 ;

45         do x = .4, .04, .004, .0004, .000000004 ;

46         if x >= .01 then y = put (x, 3.2) ;

47         else y = compress (put (x, e7.), '.0') ;

48         put x y ;

49         end ;

50         run ;

0.4 .40

0.04 .04

0.004 4E-3

0.0004 4E-4

4E-9 4E-9

Interesting that SAS does not allow users to specify e4. as a format but is able to use it internally.

Richard

All Replies
Solution
‎07-31-2014 08:19 AM
Super Contributor
Posts: 644

Re: Help to convert number to character format in scientific notation

43         data have ;

44         length y \$4 ;

45         do x = .4, .04, .004, .0004, .000000004 ;

46         if x >= .01 then y = put (x, 3.2) ;

47         else y = compress (put (x, e7.), '.0') ;

48         put x y ;

49         end ;

50         run ;

0.4 .40

0.04 .04

0.004 4E-3

0.0004 4E-4

4E-9 4E-9

Interesting that SAS does not allow users to specify e4. as a format but is able to use it internally.

Richard

New Contributor
Posts: 4