[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sas-l
Subject:    Re: significant digits format
From:       John Whittington <johnw () MAG-NET ! CO ! UK>
Date:       1997-08-30 21:14:30
[Download RAW message or body]

On Sat, 30 Aug 1997, Andrew James Llwellyn Cary <ajlcary@CARYCONSULTING.COM>
wrote:

>Tis easy.
>Define a user defined picture format using PROC FORMAT and use it to present
>the data.
>
>PROC FORMAT;
>   value sdigit
>           0- 0.0001     =[12.6]
>           0.0001-<0.001 =[11.5]
>           0.001-<0.01   =[10.4]
>           0.01 -0.1     =[9.3]
>           0.1-<1        =[8.2]
>           1-<10         =[7.1]
>           10-99999      =[5.0];
>
>This will give you two significant digits up to 10 (after which it is all
>integers).

Andrew, I suppoose that is fairly 'easy', but there are some snags.
Firstly, one needs to know in advance the range of possible values.
Secondly, you would need to write a separate format for each number of
desired 'significant digits'.  Thirdly, the way you are handling figures >10
does not corerspond to the usual meaning of 'significant figures'.  Even
though 1,234,567 is an integer, when expressed to, say, '3 significant
digits' it should really become 1,230,000.

For what it's worth, I paste in here a reply to a similar question whgich I
posted last year (varying the 'E' format alters the number of significant
figures).

-------------------
.... the most obvious concept which comes to mind if you want to define the
number of significant figures is to get the mantissa and exponent separate,
round the mantissa as required, and then convert back to a floating point
numeric.  This can be done using the E formats/informats, with PUT and INPUT
functions - and, although there in an implicit 'half way stage' of a
character variable, you never actually see it!  How about something like
(for 4 significant figures):

data test;
   input x ;
   cards ;
123456
12345.6
1234.56
123.456
12.3456
1.23456
0.123456
0.0123456
0.00123456
0.000123456
0.0000123456
;
run;

data one;
   set test ;
    z = input ( put (x, E10.), E10.) ;
run ;

proc print data=one; format x z best12.; run ;

.... which produces output:


OBS               X               Z

  1          123456          123500
  2         12345.6           12350
  3         1234.56            1235
  4         123.456           123.5
  5         12.3456           12.35
  6         1.23456           1.235
  7        0.123456          0.1235
  8       0.0123456         0.01235
  9      0.00123456        0.001235
 10     0.000123456       0.0001235
 11    0.0000123456      0.00001235

Is that roughly what you wanted?  If you want to line up the decimal points,
there's obviously a little more work to be done! The numeric part of the E
format needs to be equal to x+6 , where x is the number of significant
figures you want.

I hope this may be of some help.

Regards

John

-----------------------------------------------------------
Dr John Whittington,        Voice:      +44 1296 730225
Mediscience Services        Fax:        +44 1296 738893
Twyford Manor, Twyford,     E-mail:     johnw@mag-net.co.uk
Buckingham  MK18 4EL, UK    CompuServe: 100517,3677
-----------------------------------------------------------

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic