Date Intervals, Formats, and Functions |
Some of the SAS date and datetime formats commonly used to write out SAS date and datetime values are listed in Table 4.3 and Table 4.4. A width value can be specified with each format. The tables list the range of width values allowed and the default width value for each format.
The notation used by a format is abbreviated in different ways depending on the width option used. For example, the format MMDDYY8. writes the date 17 October 1991 as 10/17/91, while the format MMDDYY6. writes this date as 101791. In particular, formats that display the year show two-digit or four-digit year values depending on the width option. The examples shown in the tables are for the default width.
The interval function INTFMT returns a recommended format for time ID values based on the interval that describes the frequency of the values. The following example uses INTFMT to select a format to display the quarterly time ID variable qtrDate. This selected format is stored in a macro variable created by the CALL SYMPUT statement. The macro variable &FMT is then used in the FORMAT statement in the PROC PRINT step.
data b(keep=qtrDate); interval = 'QTR'; form = INTFMT( interval, 'long' ); call symput('fmt',form); do i=1 to 4; qtrDate = INTNX( interval, '01jan00'd, i-1 ); output; end; run; proc print; format qtrDate &fmt; run;
The second argument to INTFMT is 'long,' 'l,' 'short,' or 's' and controls the width of the year (2 or 4) for date formats. For more information about the INTFMT function, see SAS Language Reference: Dictionary.
See SAS Language Reference: Concepts for a complete description of these formats, including the variations of the formats produced by different width options. See Chapter 3, Working with Time Series Data, for a discussion of the use of date and datetime formats.
Copyright © 2008 by SAS Institute Inc., Cary, NC, USA. All rights reserved.