PICTURE phonepix OTHER= '(999)999-9999';
Syntax, PROC FORMAT
with the PICTURE statement:
PROC FORMAT;
PICTURE format-name <(format-options)>
<value-range-set-1 =
'template-value'
(template-options)>
<value-range-set-n
= 'template-value'
(template-options)>;
RUN;
format-name
is the name of the
format that you are creating.
Note: A user-defined format cannot
be the name of a format supplied by SAS. The name must be a valid
SAS name. A numeric format name can be up to 32 characters long.
value-range-set
specifies one or more
variable values and a template for printing those values. value-range-set has
the following form: value-or-range =
'template-value'.
value-or-range
a single value, such
as 12 or a range of values, such as 1-100.
template-value
specifies a template
for formatting values of numeric variables.
digit selectors
are numeric characters
(0 through 9) that define positions for numeric values.
directives
are special characters
that you can use in the template to format date, time, or datetime
value.
template options
are specific to the
specified template.
format options
are specific to the
format as a whole, which includes all templates created by the PICTURE
statement.
|
2<-4
range
does not include 2, but includes 4. However, 4<-<10
excludes
both 4 and 10. The keyword OTHER is used to print values and message
characters for any values that do not fall into the specified range.
proc format; picture rainamt 0-2='9.99 slight' 2<-4='9.99 moderate' 4<-<10='9.99 heavy' other='999 check value'; run; proc print data=certadv.rain; format amount rainamt.; run;
Syntax, PICTURE statement
with the DATATYPE= option:
PICTURE format-name (DEFAULT=length)
value-or-range-1='directives'
(DATATYPE=DATE|TIME|DATETIME);
RUN;
(DEFAULT=length)
specifies the default
length of the formatted value. If the DEFAULT= option is not used,
the length of the formatted value is based on the length of the longest
template.
'directives'
specifies special characters
that define a template for the display of date, time, or datetime
values. The special characters must be placed within quotation marks.
(DATATYPE=DATE | TIME | DATETIME)
enables the use of
directives in the template to format date, time, or datetime values.
The DATATYPE= option must be specified for each value-range set. The
DATATYPE= option must be placed within parentheses.
|
Directive
|
Description
|
Result
|
---|---|---|
%A
|
Weekday name in full
|
Wednesday
|
%a
|
Weekday name, the first
three letters
|
Wed
|
%d
|
Day of the month in
one or two digits
|
2 or 11
|
%0d
|
Day of month two digits
|
02
|
%B
|
Month name in full
|
January
|
%3B
|
Month name, the first
three letters
|
Jan
|
%m
|
Month number in one
or two digits
|
4 or 12
|
%0m
|
Month number in two
digits
|
04
|
%Y
|
Year in four digits
|
2019
|
%0y
|
Year in two digits
|
19
|
Directive
|
Description
|
Result
|
---|---|---|
%H
|
Hour, 24-hour clock
in one or two digits
|
21
|
%0H
|
Hour, 24-hour clock
in two digits with a leading zero
|
021
|
%I
|
Hour, 12-hour clock
in one or two digits
|
9
|
%0I
|
Hour, 12-hour clock
in two digits with a leading zero
|
09
|
%M
|
Minute in one or two
digits
|
13
|
%0M
|
Minute, in two digits
with a leading zero
|
013
|
%S
|
Second in one or two
digits
|
5
|
%0S
|
Second in two digits
with a leading zero
|
05
|
%p
|
AM or PM
|
PM
|
proc format; picture mydate (default=10) low-high='%0d-%3b%Y' (datatype=date); run; proc print data=certadv.empdata (keep=division hireDate lastName obs=5); format hiredate mydate.; run;
Syntax, PICTURE statement
using digit selectors:
PICTURE format-name (ROUND DEFAULT=length)
value-or-range-1='digit
selectors with non-numeric characters'
(MULT | MULTIPLIER=n PREFIX='prefix');
RUN;
(ROUND)
rounds the value to
the nearest integer.
(MULT | MULTIPLIER=n)
specifies a number
to multiply the value by.
(PREFIX='prefix')
specifies a character
string to place in front of the formatted value.
|
picture Discount (round) low-high='009.9%' (multiplier=10);
proc format; picture Discount low-high='009.0%' (multiplier=10); run; data work.customerdiscount; set certadv.grocery; format CustomDiscount Discount.; run; proc print data=work.customerdiscount noobs; run;
proc format; picture NewPrice low-high='000,009.99' (prefix='$'); run; data work.newprice; set work.customerdiscount; NewPrice=Price-(Price*(CustomDiscount*0.01)); format NewPrice NewPrice. CustomDiscount Discount.; run; proc print data=work.newprice; run;
proc format; picture Discount low-high='009.0%' (multiplier=10); picture NewPrice low-high='000,009.99' (prefix='$'); picture Diff (round) low-high='000,009.99' (prefix='$'); run; data work.newPriceTot; set certadv.grocery; NewPrice=Price-(Price*(CustomDiscount*0.01)); Difference=Price-NewPrice; format CustomDiscount Discount. NewPrice NewPrice. Difference Diff.; run; proc print data=work.newPriceTot; run;
proc format; picture dollar_KM (round default=7) low-<1000='009' (prefix='$' multiplier=1) 1000-<1000000='009.9K' (prefix='$' multiplier=.01) 1000000-high='009.9M' (prefix='$' multiplier=.00001); run;
proc print data=certadv.values noobs;
format MultiValues 12.5
FormattedValues dollar_KM.;
run;