Working with Time Series Data |
Computing Dates from Calendar Variables |
The MDY function converts MONTH, DAY, and YEAR values to a SAS date value. For example, MDY(2010,17,91) returns the SAS date value ’17OCT2010’D.
The YYQ function computes the SAS date for the first day of a quarter. For example, YYQ(2010,4) returns the SAS date value ’1OCT2010’D.
The DATEJUL function computes the SAS date for a Julian date. For example, DATEJUL(91290) returns the SAS date ’17OCT2010’D.
The YYQ and MDY functions are useful for creating SAS date variables when the ID values recorded in the data are year and quarter; year and month; or year, month, and day.
For example, the following statements read quarterly data from records in which dates are coded as separate year and quarter values. The YYQ function is used to compute the variable DATE.
data usecon; input year qtr gnp; date = yyq( year, qtr ); format date yyqc.; datalines; 1990 1 5375.4 1990 2 5443.3 ... more lines ...
The monthly USCPI data shown in a previous example contained time ID values represented in the MONYY format. If the data records instead contain separate year and month values, the data can be read in and the DATE variable computed with the following statements:
data uscpi; input month year cpi; date = mdy( month, 1, year ); format date monyy.; datalines; 6 90 129.9 7 90 130.4 ... more lines ...
Copyright © SAS Institute, Inc. All Rights Reserved.