Computing Dates from Calendar Variables Computing Dates from Calendar Variables Working with Time Series Data
The MDY function converts MONTH, DAY, and YEAR values to a SAS date value. For example, MDY(10,17,91) returns the SAS date value ’17OCT91’D.
The YYQ function computes the SAS date for the first day of a quarter. For example, YYQ(91,4) returns the SAS date value ‘1OCT91’D.
The DATEJUL function computes the SAS date for a Julian date. For example, DATEJUL(91290) returns the SAS date ’17OCT91’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, instead of dates that can be read with a date informat.
For example, the following statements read quarterly estimates of the gross national product of the U.S. from 1990:I to 1991:II from data records on 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 1990 3 5514.6 1990 4 5527.3 1991 1 5557.7 1991 2 5615.8 ;
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 8 90 131.6 … etc. … ;
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.