BookmarkSubscribeRSS Feed
whymath
Lapis Lazuli | Level 10

When I submit this program:

data test;
  input x;
  if _n_=1 then put 11*'-' '1' 11*'-' '2' 11*'-' '3' 11*'-' '4';
  put x bestd12.1 x bestd12.2 x bestd12.3 x bestd12.4;
  cards;
  12.1
  12
  12.12
  12.123
  12.1234
  ;
run;

The Log window shows:

-----------1-----------2-----------3-----------4
    12.10000    12.10000   12.100000   12.100000
          12          12          12          12
    12.12000    12.12000   12.120000   12.120000
    12.12300    12.12300   12.123000   12.123000
    12.12340    12.12340   12.123400   12.123400

Why bestd12.2 just behave all the same with bestd12.1? And also bestd12.3 and bestd12.4. How does the p influence BESTDw.p format?

9 REPLIES 9
ballardw
Super User

I think this from the online description of the format may help:

The BESTDw.p format writes numbers so that the decimal point aligns in groups of values with similar magnitude. Integers are printed without a decimal point. Larger values of p print the data values with more precision and potentially more shifts in the decimal point alignment. Smaller values of p print the data values with less precision and a greater chance of decimal point alignment.
The format chooses the number of decimal places to print for ranges of values, even when the underlying values can be represented with fewer decimal places.

Remember that part of the purpose of this format is to align decimals. So the p isn't a fix display as in format like F8.2 but makes attempts to display similar ranges of values with the same decimal point location and number of displayed decimal points.

 

If you really want to control the number of displayed decimal points then use formats other than BEST or BESTD

 

whymath
Lapis Lazuli | Level 10
Thank you, Ballardw. I've looked at this webpage but didn't get what I want, how do you think the relationship between p and the number of decimal places should be described?
ballardw
Super User

Since I can't tell what you "want" I have no idea how to expand on what is in the documentation.

whymath
Lapis Lazuli | Level 10
I'm looking for the functional relationship between p and the number of decimal places being displayed.
Sajid01
Meteorite | Level 14

Hello @whymath 
I see what you are asking about.
BESTDw.p simply aligns the digit as pointed by @ballardw .
BESTDw.p documentation describes p as precision, but I don't see it doing that. What one would have expected is to\hat the format would round off the value at the pth position from decimal. (https://simple.wikipedia.org/wiki/Arithmetic_precision ).
May be somebody from SAS can elaborate on this.

whymath
Lapis Lazuli | Level 10
It's great that you understand me, still on the way to solve this.
ballardw
Super User

@whymath wrote:
It's great that you understand me, still on the way to solve this.

What would a "solution" look like?

I am afraid that you may be asking for some proprietary code from SAS for an exhaustive answer as I'm moderately certain that writing proc format code isn't how this format is defined.

 

BESTD is basically a guessing format based on the ranges of values of variables, and quite likely numbers of values involved. You might have a "solution" for one data set, add a single value and the solution gets thrown out the window because new groups of decimals are displayed.

Sajid01
Meteorite | Level 14

Hello @whymath 
Given the way  this format work, in my opinion, the appropriate approach would be to request SAS for the features as you expect it to have at SAS Product Suggestions - SAS Support Communities

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 9 replies
  • 563 views
  • 1 like
  • 4 in conversation