Trying to make sense of the "D" numeric format, and when best to use it.
And why a "put(12345,D32.9)" yields " 12345.0000000000000000" (16 zeroes)?
Why use D32.9 when I could use 32.16?
The documentation seems a bit hard to decypher (summary below).
Any assistance appreciated - use cases, perhaps?
Dx.p format - SAS(R) 9.4 Formats and Informats: Reference
Prints numeric values, possibly with a great range of values, lining up decimal places for values of similar magnitude.
Details - The Dw.p format writes numbers so that the decimal point aligns in groups of values with similar magnitude. 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.
Comparisons
The same code yields 19 zeros for me.
%put &=sysscpl &=sysvlong %sysfunc(putn(12345,D32.9));
SYSSCPL=X64_SRV12 SYSVLONG=9.04.01M2P072314 12345.0000000000000000000
I've tried 32.0 up to 32.9 (32.0 is same as 32.3). The result is still MORE decimals than
So I guess I'm looking for clear documentation on what the "D" format is actually FOR, and how to know - with certainty - what the output would be for various values of width and/or decimal.
Background: I'm storing the result in strings, and I need to know the length of the strings and the placement of the decimal point.
> I need to know the length of the strings and the placement of the decimal point.
Why use format Dw.p then?
Its description
Prints numeric values, possibly with a great range of values, lining up decimal places for values of similar magnitude.
is enticing for your purpose, but the small-print caveat
Smaller values of p print the data values with less precision and a greater chance of decimal point alignment.
includes the word chance, which is not what you seem to want.
A fixed format like w.d seems more suitable for your purpose, doesn't it?
I never used format Dw.p before, so am unsure how precision parameter works. As you rightly point out, the documentation is rather terse on the matter.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.