SAS Picture formats – without fear (or tears)
The PICTURE format is part of the user-defined formats that you can create using PROC FORMAT.
A simple example is: picture pay
low-high = '000,009.99' (prefix='$'); This format means that eight (8) digits can be displayed, including the prefix. If the number is too big, the prefix is omitted –” You have to guess…”
The problem: When the number is too big, and probably is important to the user, only the last digits are used. These are the ones of least importance. data work.test; do i= 1 to 10; num= 1.234567890*10**(i-4); put num pay.; end; run; The result in SAS Log:
$0.00
$0.01
$0.12
$1.23
$12.34
$123.45
$1,234.56
$12,345.67
123,456.78 ßß Dollar? Pound ??
234,567.89 ßß ERROR – Where did 1 Million dollars go?
One solution: Define an ordinary format, using the VALUE statement, and imbed the PICTURE format in this. Below is a simple example. When the number is outside the range of the picture format, ordinary formats will be used instead. The risk that any number is shown in the wrong way, is much smaller.
proc format;
picture pay
low-high='000,009.99' (prefix='$');
value goodpay
low - 0.01 = [comma8.]
0.01 - 99999 = [pay.] /* The pay defined above. */
99999-high = [comma8.]; run;
data work.test;
do i= 1 to 12;
num= 1.234567890*10**(i-4);
put num pay. " " num goodpay.;
end;
run;
The result from SAS log, put in a table:
pay
Comment to PAY format
goodpay
Comment to goodpay
$0.00
0
$0.01
$0.01
$0.12
$0.12
$1.23
$1.23
$12.34
$12.34
$123.45
$123.45
$1,234.56
$1,234.56
$12,345.67
$12,345.67
123,456.78
Dollar or Pound?
123,457
Dollar or pound?
234,567.89
One million missing
1234568
Correctly rounded
345,678.89
10 millions missing
12345679
Correctly rounded
456,788.99
100 millions missing
1.2346E8
Correct thanks to E-format
I hope that this may be of some use.
/Br Anders Skollermo
... View more