BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
japelin
Rhodochrosite | Level 12

This is a Windows 64bit environment.

 

When the following program is executed, the

data _null_;
  value=12345678;
  put 'best4.> ' value best4. /
      'best5.> ' value best5. /
      'best6.> ' value best6. /
      'best7.> ' value best7.;
run;

The results are as follows

best4.> 12E6
best5.> 123E5
best6.> 1.23E7
best7.> 1.235E7

 

Here we see that
Why does best5 format print as 123E5 instead of 1.2E7?
Why does best6 format print as 1.23E7 instead of 1234E4?
I can't figure it out by looking at Help.

 

The printed results of best5 format. and best6. are different in expression, but they have the same value, right?(12300000)
Since the length of the format changes, doesn't the number of significant digits also change?
Why is it that the number of significant digits changes, but the actual value is the same?
I don't get it.

 

If anyone knows, please let me know.

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

The logic as length grows seems to be: Add significant digits, when you have 3 significant digits, add a decimal point, and then add more digits.

That's just what the format does.

 

View solution in original post

8 REPLIES 8
ballardw
Super User

The BEST format exponential notation doesn't care about "significant digits" as so many users have different rules for what is significant.

If you care, then do not use BEST formats which uses general rules, based on ranges of values, to display values within a fixed number of characters. Use the E format if want to control things a bit better.

 

You should include negative values when playing with such examples as well to see what effect the extra character for negative does to values.

japelin
Rhodochrosite | Level 12
Thanks.
I've tried outputting best1-32 for various numbers, negative numbers of course, and numbers with decimals, but I couldn't figure out the law at all.
I don't want to know how to display the values, I simply want to know the law of exponential notation in BEST format.
Why? Is it because I am a spec idiot? 😛
Tom
Super User Tom
Super User

The idea of the BEST format is that it will pick the best way to display the value in the number of characters you requested.  "123E5" is better than "1.2E7" because by eliminating the decimal point it can include one extra digit and still fit into only 5 characters.

 

You would have to talk to SAS about how SAS decides what is "BEST".

japelin
Rhodochrosite | Level 12

The idea of the BEST format is that it will pick the best way to display the value in the number of characters you requested.  "123E5" is better than "1.2E7" because by eliminating the decimal point it can include one extra digit and still fit into only 5 characters.

Based on your way of thinking, it seems that 1234E4 would be superior to 1.23E7.

 


You would have to talk to SAS about how SAS decides what is "BEST".


I think that's exactly right, but this kind of "specification" is not disclosed to the public.
So, I tried to guess from the results, but I couldn't figure it out.

Tom
Super User Tom
Super User

And given how SAS normally maintains backwards compatibility they are not likely to change the algorithm to start having 12345678 display with BEST6. as "1234E4" instead of "1.23E7".

 

ChrisNZ
Tourmaline | Level 20

The logic as length grows seems to be: Add significant digits, when you have 3 significant digits, add a decimal point, and then add more digits.

That's just what the format does.

 

japelin
Rhodochrosite | Level 12

That tends to be the case.

The rest seems to depend on the value, as shown below.

 

data _null_;
  a=10000;
  put a=best4.;
  a=11000;
  put a=best4.;
run;

Results:

a=1E4
a=11E3

lol

ChrisNZ
Tourmaline | Level 20

zeros are not significant digits then...

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1957 views
  • 2 likes
  • 4 in conversation