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?
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
Since I can't tell what you "want" I have no idea how to expand on what is in the documentation.
Add numbers to your dataset which are larger (>100), smaller (<0) and have more significant digits to see possible effects.
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 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.
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
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.