Picture Format: Bug?

Accepted Solution Solved
Reply
Respected Advisor
Posts: 4,173
Accepted Solution

Picture Format: Bug?

Using 2 almost identical picture formats I've encountered a weird behaviour (see below). Am I missing something here or is this a bug.

proc format;
  picture num1_pict
    other     = '009.90000000'
    ;
  picture num2_pict
    other     = '009.90000'
    ;
quit;

data _null_;
  var1=17.9;
  var2=17.9;
  put var1= num1_pict.;
  put var2= num2_pict.;
run;

Result:
var1=17.89999999
var2=17.90000

OS: Win7 64bit

SAS version: 9.4 1M0


Accepted Solutions
Solution
‎05-23-2014 05:11 AM
Respected Advisor
Posts: 3,799

Re: Picture Format: Bug?

It rounds after the implied or explicit multiplier is applied.  You need to understand how PICTURE formats work.

ROUND

rounds the value to the nearest integer before formatting. Without the ROUND option, the format multiplies the variable value by the multiplier, truncates the decimal portion (if any), and prints the result according to the template that you define. With the ROUND option, the format multiplies the variable value by the multiplier, rounds that result to the nearest integer, and then formats the value according to the template. Note that if the FUZZ= option is also specified, the rounding takes place after SAS has used the fuzz factor to determine which range the value belongs to.

View solution in original post


All Replies
Super User
Posts: 7,762

Re: Picture Format: Bug?

I've seen similar behaviour with simple (w.d) formats. When you specify enough fractional digits, you can suddenly see the little errors introduced by the 8-byte real number format.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Trusted Advisor
Posts: 3,212

Re: Picture Format: Bug?

Indeed kurt is right, it is quite normal behavior. For more background see: http://support.sas.com/techsup/technote/ts230.pdf

---->-- ja karman --<-----
Respected Advisor
Posts: 3,799

Re: Picture Format: Bug?

The ROUND option address that issue. I can't think of a scenario with decimal picture where round is not appropriate. 

proc format;
 
picture num1_pict(round)
    other     =
'009.90000000'
    ;
  picture num2_pict(round)
    other     =
'009.90000'
    ;
quit;
data _null_;
  var1=
17.9;
  var2=
17.9;
 
put var1= num1_pict.;
 
put var2= num2_pict.;
run;
Trusted Advisor
Posts: 3,212

Re: Picture Format: Bug?

Posted in reply to data_null__

@ data_null, could be not always be as easy. Base SAS(R) 9.4 Procedures Guide, Second Edition (round - rounds to nearest integer)
The precision of numbers will always be a problematic one needing about 12 digits (15 is limit) 

---->-- ja karman --<-----
Solution
‎05-23-2014 05:11 AM
Respected Advisor
Posts: 3,799

Re: Picture Format: Bug?

It rounds after the implied or explicit multiplier is applied.  You need to understand how PICTURE formats work.

ROUND

rounds the value to the nearest integer before formatting. Without the ROUND option, the format multiplies the variable value by the multiplier, truncates the decimal portion (if any), and prints the result according to the template that you define. With the ROUND option, the format multiplies the variable value by the multiplier, rounds that result to the nearest integer, and then formats the value according to the template. Note that if the FUZZ= option is also specified, the rounding takes place after SAS has used the fuzz factor to determine which range the value belongs to.

Respected Advisor
Posts: 4,173

Re: Picture Format: Bug?

Posted in reply to data_null__

Thanks Jaap and data_null.

I thought I have been aware of the numeric precision "challenge" but I've never realised so far that this also applies within the same SAS instance when using formats for printing.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 332 views
  • 3 likes
  • 4 in conversation