Restriction: | National language format directives can be used in the PICTURE statement only under DBCS and UTF-8 environments. |
Tips: | As
a best practice, if you specify an existing format in a value-range-set,
always specify a default value by using the DEFAULT= option. If you are formatting DBCS characters, use the DEFAULT= option to set the default format width to be large enough to format these characters. Without setting the DEFAULT= option, the default width of a format is the width of the largest value to the right of the equation symbol. |
See: | SAS Formats and Informats: Reference and SAS National Language Support (NLS): Reference Guide for documentation about formats that are supplied by SAS. |
Examples: | Creating a Picture Format |
value levels (fuzz=.2) 1='A' 2='B' 3='C';
B
.
Afrikaans | English | Macedonian | Spanish |
Catalan | Finnish | Norwegian | Swedish |
Croatian | French | Polish | Swiss_French |
Czech | German | Portuguese | Swiss_German |
Danish | Hungarian | Russian | |
Dutch | Italian | Slovenian |
picture abc (multilabel) 1000='9,999' 1000='9999'; picture overlap (multilabel) /* without decimals */ 0-999='999' 1000-9999='9,999' /* with decimals */ 0-9='9.999' 10-99='99.99' 100-999='999.9';
$1.6M
: picture million low-high='09.9M' (prefix='$' mult=.00001);
>1000 miles
: picture miles 1-1000='0000' 1000<-high='>1000 miles'(noedit);
$25,500.00
:
picture pay low-high='000,009.99' (prefix='$');
illegal
day value
). Because the DAYS. format has nonzero
digit selectors, values are printed with leading zeros. The special
range OTHER prints the message characters for any values that do not
fall into the specified range (1 through 31). picture days 01-31='99' other='99-illegal day value';
02 67-illegal day value
data sample; format Amount nozeros.; input Amount; datalines; -2.051 -.05 -.017 0 .093 .54 .556 6.6 14.63 0.996 -0.999 -45.00 ; run;
proc format; picture nozeros (round) low - -1 = '000.00' (prefix='-') -1 < - < -.99 = '9.99' (prefix='-' mult=100) -0.99 <-< 0 = '99' (prefix='-.' mult=100) 0 = '9.99' 0 < -< .99 = '99' (prefix='.' mult=100) 0.99 - < 1 = '9.99' (mult=100) 1 - high = '09.99'; run;
Multiply the number
by the MULT= value. If you do not specify the MULT= option, then the
PICTURE statement uses the default. The default is 10n,
where n is the number of
digit selectors to the right of the decimal 1 in the picture. (Step 6 discusses
digit selectors further.)
|
Specifying a MULT= value
is necessary for numbers between 0 and 1 and numbers between 0 and
−1 because no decimal appears in the pictures for those ranges.
Because MULT= defaults to 1, truncation of the significant digits
results without a MULT= value specified. (Truncation is explained
in the next step.) For the three ranges that do not have MULT= values
specified, the MULT= value defaults to 100 because the corresponding
picture has two digit selectors to the right of the decimal. After
the MULT= value is applied, all significant digits are moved to the
left of the decimal.
|
|
Turn the number into
a character string. If the number is shorter than the picture, then
the length of the character string is equal to the number of digit
selectors in the picture. Pad the character string with leading zeros.
(The results are equivalent to using the Zw. format.
Zw. is explained in the section
on SAS formats in SAS Formats and Informats: Reference.
|
The numbers 205, 5,
and 660 become the character strings
0205 , 005 ,
and 0660 , respectively. Because each
picture is longer than the numbers, the format adds a leading zero
to each value. The format does not add leading zeros to the number
56 because the corresponding picture has only two digit selectors.
|
|
Apply the character
string to the picture. The format only maps the rightmost n
characters in the character string, where n
is the number of digit selectors in the picture. Thus, it is important
to make sure that the picture has enough digit selectors to accommodate
the characters in the string.
After the format takes
the right-most n characters,
it then maps those characters to the picture from left to right. Choosing
a zero or nonzero digit selector is important if the character string
contains leading zeros. If one of the leading zeros in the character
string maps to a nonzero digit selector, then it and all subsequent
leading zeros become part of the formatted value. If all of the
leading zeros map to zero digit selectors, then none of the leading
zeros become part of the formatted value. The format replaces the
leading zeros in the character string with blanks. 2
|
||
Prefix any characters
that are specified in the PREFIX= option. You need the PREFIX= option
because when a picture contains any digit selectors, the picture
must begin with a digit selector. Thus, you cannot begin your picture
with a decimal point, minus sign, or any other character that is
not a digit selector.
|
||
1A decimal in a PREFIX= option is not part of the picture. | ||
2You can use the FILL= option to specify a character other than a blank to become part of the formatted value. |
proc print data=sample noobs; format amount nozeros.; title 'Formatting the Variable Amount'; title2 'with the NOZEROS. Format'; run;