In SAS® code, formats determine how variable values are printed. However, sometimes the format supplied by the SAS® System for date or datetime variables do not give you exactly the display format that you want. For example, consider the SAS QTRw. format, which only displays a date variable value as the quarter of the year (1, 2, 3 or 4). If you want to display the quarters as QTR1, QTR2, QTR3 or QTR4 instead of just as numbers, SAS does not have a format to accomplish such a display. However, you can use format options in the FORMAT procedure's PICTURE statement to create a mask (or picture) that instructs SAS to append the quarter number to your desired text string.
In general, PROC FORMAT enables you to define your own formats for variables in order to change the way the variables display or print in procedure output. With formats, you can do the following:
The syntax for the PICTURE statement in PROC FORMAT is as follows:
PICTURE name <(format-option(s))> <value-range-set-1
<(picture-1-option(s))> <...value-range-set-n
<(picture-n-option(s))>>;
The following program illustrates a custom PICTURE format that is used to generate a custom format for a quarter from a date variable. The DATATYPE= option specifies a special directive for the date variable's display. In the program, %q is replaced with the value 1, 2, 3 or 4 in the string Qtr%q. For more information about using date or datetime directives in PICTURE formats, see "The FORMAT Procedure" in the Base SAS® 9.2 Procedures Guide.
Example
If you look at the SAS log, you will see the following output:
The following output is generated by PROC PRINT in the SAS Output window:
Product Family | Product | System | SAS Release | |
Reported | Fixed* | |||
SAS System | Base SAS | z/OS | ||
OpenVMS VAX | ||||
Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
Microsoft Windows XP 64-bit Edition | ||||
Microsoft® Windows® for x64 | ||||
OS/2 | ||||
Microsoft Windows 95/98 | ||||
Microsoft Windows 2000 Advanced Server | ||||
Microsoft Windows 2000 Datacenter Server | ||||
Microsoft Windows 2000 Server | ||||
Microsoft Windows 2000 Professional | ||||
Microsoft Windows NT Workstation | ||||
Microsoft Windows Server 2003 Datacenter Edition | ||||
Microsoft Windows Server 2003 Enterprise Edition | ||||
Microsoft Windows Server 2003 Standard Edition | ||||
Microsoft Windows Server 2008 | ||||
Microsoft Windows XP Professional | ||||
Windows 7 Enterprise 32 bit | ||||
Windows 7 Enterprise x64 | ||||
Windows 7 Home Premium 32 bit | ||||
Windows 7 Home Premium x64 | ||||
Windows 7 Professional 32 bit | ||||
Windows 7 Professional x64 | ||||
Windows 7 Ultimate 32 bit | ||||
Windows 7 Ultimate x64 | ||||
Windows Millennium Edition (Me) | ||||
Windows Vista | ||||
64-bit Enabled AIX | ||||
64-bit Enabled HP-UX | ||||
64-bit Enabled Solaris | ||||
ABI+ for Intel Architecture | ||||
AIX | ||||
HP-UX | ||||
HP-UX IPF | ||||
IRIX | ||||
Linux | ||||
Linux for x64 | ||||
Linux on Itanium | ||||
OpenVMS Alpha | ||||
OpenVMS on HP Integrity | ||||
Solaris | ||||
Solaris for x64 | ||||
Tru64 UNIX |
Type: | Usage Note |
Priority: |
Date Modified: | 2010-03-04 07:24:41 |
Date Created: | 2010-02-19 10:36:35 |