SAS: decimal place issues

  • Follow


Hey, Guys,

This question really bothers me:


I have a= 4800.000, b=0.5316742081 and c=(a-b) /b *100.


If the code runs dependtly , the  c with best. is  c=902708.51071.


But when the code is part of a large  program, it gives me the value
of c=902708.51064 unless I play some tricks such as
d =input(put(b, best12.), best12.);
c=(a-d)/d*100, I could get c=902708.51071 as expected.


I use "put" to print out the data in the large program with best.
format, and the value of a and b is just as I listed above. So I
think
SAS should use a=4800.000 and b=0.5316742081 when calculate c,
but ...


The data of a and b is displayed with format=8.3 in orginal feeding
data set, but I think it should not matter. Anyway, no clue ...


Any comments are really appreciated.


Thanks a lot,
Mindy




0
Reply master2005_sas (161) 6/3/2010 4:45:58 PM

On Jun 3, 11:45=A0am, Mindy <master2005_...@yahoo.com> wrote:
> Hey, Guys,
>
> This question really bothers me:
>
> I have a=3D 4800.000, b=3D0.5316742081 and c=3D(a-b) /b *100.
>
> If the code runs dependtly , the =A0c with best. is =A0c=3D902708.51071.
>
> But when the code is part of a large =A0program, it gives me the value
> of c=3D902708.51064 unless I play some tricks such as
> d =3Dinput(put(b, best12.), best12.);
> c=3D(a-d)/d*100, I could get c=3D902708.51071 as expected.
>
> I use "put" to print out the data in the large program with best.
> format, and the value of a and b is just as I listed above. So I
> think
> SAS should use a=3D4800.000 and b=3D0.5316742081 when calculate c,
> but ...
>
> The data of a and b is displayed with format=3D8.3 in orginal feeding
> data set, but I think it should not matter. Anyway, no clue ...
>
> Any comments are really appreciated.
>
> Thanks a lot,
> Mindy

I expect rounding with regards to calculation of A and/or B in the
"large program".  Just becasue you see 4800 doesn't mean that is the
actual value.  For example.

306  data _null_;
307     aa=3D4800;
308     a=3D 4800.000-2e-7;
309     b=3D0.5316742081;
310     c=3D(a-b) /b *100.;
311     put (_all_)(=3D);
312     format a 8.3;
313     put (_all_)(=3Dhex16.);
314  run;

aa=3D4800 a=3D4800.000 b=3D0.5316742081 c=3D902708.51068
aa=3D40B2C00000000000 a=3D40B2BFFFFFFCA502 b=3D3FE10379A0FD517F
c=3D412B8C6905776C31

Use HEX16 format in your large program see if the value of A and B are
actually what you think they are.
0
Reply data 6/3/2010 6:19:02 PM


On Jun 3, 6:45=A0pm, Mindy <master2005_...@yahoo.com> wrote:
> Hey, Guys,
>
> This question really bothers me:
>
> I have a=3D 4800.000, b=3D0.5316742081 and c=3D(a-b) /b *100.
>
> If the code runs dependtly , the =A0c with best. is =A0c=3D902708.51071.
>
> But when the code is part of a large =A0program, it gives me the value
> of c=3D902708.51064 unless I play some tricks such as
> d =3Dinput(put(b, best12.), best12.);
> c=3D(a-d)/d*100, I could get c=3D902708.51071 as expected.
>
> I use "put" to print out the data in the large program with best.
> format, and the value of a and b is just as I listed above. So I
> think
> SAS should use a=3D4800.000 and b=3D0.5316742081 when calculate c,
> but ...
>
> The data of a and b is displayed with format=3D8.3 in orginal feeding
> data set, but I think it should not matter. Anyway, no clue ...
>
> Any comments are really appreciated.
>
> Thanks a lot,
> Mindy

I am guessing that the value of b has more decimal places and that you
are using a format to view it that obscures these extra decimal
places. I added "45" to the value of b at the end and I get the same
result you did.

114  data _null_;
115  a=3D 4800.000;
116  b=3D0.531674208145;
117  c=3D(a-b)/b*100;
118  put c=3D;
119  run;

c=3D902708.51064
0
Reply RolandRB 6/5/2010 7:01:12 AM

On Jun 3, 11:19=A0am, "data _null_;" <datan...@gmail.com> wrote:
> On Jun 3, 11:45=A0am,Mindy<master2005_...@yahoo.com> wrote:
>
>
>
>
>
> > Hey, Guys,
>
> > This question really bothers me:
>
> > I have a=3D 4800.000, b=3D0.5316742081 and c=3D(a-b) /b *100.
>
> > If the code runs dependtly , the =A0c with best. is =A0c=3D902708.51071=
..
>
> > But when the code is part of a large =A0program, it gives me the value
> > of c=3D902708.51064 unless I play some tricks such as
> > d =3Dinput(put(b, best12.), best12.);
> > c=3D(a-d)/d*100, I could get c=3D902708.51071 as expected.
>
> > I use "put" to print out the data in the large program with best.
> > format, and the value of a and b is just as I listed above. So I
> > think
> > SAS should use a=3D4800.000 and b=3D0.5316742081 when calculate c,
> > but ...
>
> > The data of a and b is displayed with format=3D8.3 in orginal feeding
> > data set, but I think it should not matter. Anyway, no clue ...
>
> > Any comments are really appreciated.
>
> > Thanks a lot,
> >Mindy
>
> I expect rounding with regards to calculation of A and/or B in the
> "large program". =A0Just becasue you see 4800 doesn't mean that is the
> actual value. =A0For example.
>
> 306 =A0data _null_;
> 307 =A0 =A0 aa=3D4800;
> 308 =A0 =A0 a=3D 4800.000-2e-7;
> 309 =A0 =A0 b=3D0.5316742081;
> 310 =A0 =A0 c=3D(a-b) /b *100.;
> 311 =A0 =A0 put (_all_)(=3D);
> 312 =A0 =A0 format a 8.3;
> 313 =A0 =A0 put (_all_)(=3Dhex16.);
> 314 =A0run;
>
> aa=3D4800 a=3D4800.000 b=3D0.5316742081 c=3D902708.51068
> aa=3D40B2C00000000000 a=3D40B2BFFFFFFCA502 b=3D3FE10379A0FD517F
> c=3D412B8C6905776C31
>
> Use HEX16 format in your large program see if the value of A and B are
> actually what you think they are.- Hide quoted text -
>
> - Show quoted text -

Thanks a lot. I will test it tomorrow. __ Mindy
0
Reply master2005_sas (161) 6/9/2010 4:58:34 AM

On Jun 5, 12:01=A0am, RolandRB <rolandbe...@hotmail.com> wrote:
> On Jun 3, 6:45=A0pm,Mindy<master2005_...@yahoo.com> wrote:
>
>
>
>
>
> > Hey, Guys,
>
> > This question really bothers me:
>
> > I have a=3D 4800.000, b=3D0.5316742081 and c=3D(a-b) /b *100.
>
> > If the code runs dependtly , the =A0c with best. is =A0c=3D902708.51071=
..
>
> > But when the code is part of a large =A0program, it gives me the value
> > of c=3D902708.51064 unless I play some tricks such as
> > d =3Dinput(put(b, best12.), best12.);
> > c=3D(a-d)/d*100, I could get c=3D902708.51071 as expected.
>
> > I use "put" to print out the data in the large program with best.
> > format, and the value of a and b is just as I listed above. So I
> > think
> > SAS should use a=3D4800.000 and b=3D0.5316742081 when calculate c,
> > but ...
>
> > The data of a and b is displayed with format=3D8.3 in orginal feeding
> > data set, but I think it should not matter. Anyway, no clue ...
>
> > Any comments are really appreciated.
>
> > Thanks a lot,
> >Mindy
>
> I am guessing that the value of b has more decimal places and that you
> are using a format to view it that obscures these extra decimal
> places. I added "45" to the value of b at the end and I get the same
> result you did.
>
> 114 =A0data _null_;
> 115 =A0a=3D 4800.000;
> 116 =A0b=3D0.531674208145;
> 117 =A0c=3D(a-b)/b*100;
> 118 =A0put c=3D;
> 119 =A0run;
>
> c=3D902708.51064- Hide quoted text -
>
> - Show quoted text -

Thanks for considering the question. It did give me some thoughts. I
will re_check the whole program tomorrow. ___ Mindy
0
Reply master2005_sas (161) 6/9/2010 4:59:42 AM

On Jun 8, 11:59=A0pm, Mindy <master2005_...@yahoo.com> wrote:
> On Jun 5, 12:01=A0am, RolandRB <rolandbe...@hotmail.com> wrote:
>
>
>
>
>
> > On Jun 3, 6:45=A0pm,Mindy<master2005_...@yahoo.com> wrote:
>
> > > Hey, Guys,
>
> > > This question really bothers me:
>
> > > I have a=3D 4800.000, b=3D0.5316742081 and c=3D(a-b) /b *100.
>
> > > If the code runs dependtly , the =A0c with best. is =A0c=3D902708.510=
71.
>
> > > But when the code is part of a large =A0program, it gives me the valu=
e
> > > of c=3D902708.51064 unless I play some tricks such as
> > > d =3Dinput(put(b, best12.), best12.);
> > > c=3D(a-d)/d*100, I could get c=3D902708.51071 as expected.
>
> > > I use "put" to print out the data in the large program with best.
> > > format, and the value of a and b is just as I listed above. So I
> > > think
> > > SAS should use a=3D4800.000 and b=3D0.5316742081 when calculate c,
> > > but ...
>
> > > The data of a and b is displayed with format=3D8.3 in orginal feeding
> > > data set, but I think it should not matter. Anyway, no clue ...
>
> > > Any comments are really appreciated.
>
> > > Thanks a lot,
> > >Mindy
>
> > I am guessing that the value of b has more decimal places and that you
> > are using a format to view it that obscures these extra decimal
> > places. I added "45" to the value of b at the end and I get the same
> > result you did.
>
> > 114 =A0data _null_;
> > 115 =A0a=3D 4800.000;
> > 116 =A0b=3D0.531674208145;
> > 117 =A0c=3D(a-b)/b*100;
> > 118 =A0put c=3D;
> > 119 =A0run;
>
> > c=3D902708.51064- Hide quoted text -
>
> > - Show quoted text -
>
> Thanks for considering the question. It did give me some thoughts. I
> will re_check the whole program tomorrow. ___ Mindy- Hide quoted text -
>
> - Show quoted text -

You can try to add a format statement in the proc print . It could be
a rounding issue. Don't use best12 because it is not decimal friendly.
Try specify the number of digit after decimal.
0
Reply linjin886 (1) 6/9/2010 1:58:43 PM

5 Replies
354 Views

(page loaded in 0.648 seconds)

Similiar Articles:













7/23/2012 12:02:17 AM


Reply: