Extracting Month and Year from a SAS Date - SAS Programming

What day of the week was July 4,1776? How can you create variables that represent the YEAR and MONTH for a given date? SAS software has a number of very useful date functions to answer these and other questions.The next two examples demonstrate representative situations.Suppose you have a SAS data set FUND which contains fund drive information. Included are variables DATE (date of donation, stored as a SAS date value) and AMOUNT (amount of donation).You would like charts showing donation AMOUNT by year and month. Here is the program:

Example

DATA TEMP;
SET FUND;
YEAR=YEAR (DATE);
MONTH=MONTH (DATE);
RUN?
PRQC CHART DATA=TEMP;
VBAR YEAR/SUMVAR=AMOUNT DISCRETE;
VBAR MONTH/SUMVAR=AMOUNT DISCRETE;
RUN;

You need only use the YEAR and MONTH functions to extract the appropriate information from DATE.The YEAR function returns a four-digit year; the MONTH function returns a number from 1 to 12.You might want to create a user-defined format for MONTH with 1='JAN', etc."PROC CHART," has more details on the CHART procedure.

Computing Date Intervals

The remaining examples in this chapter cover the INTCK and INTNX functions. These functions are used to compute the number of intervals between two dates and the date after which a given number of intervals has occurred, respectively. Interval units can be one of the following:DAY, WEEK,TENDAY, SEMIMONTH, MONTH, QUARTER (QTR), SEMIYEAR, or YEAR. There is also a WEEKDAY interval which allows you to count the number of working days, specifying which day(s) of the week will be days off. These functions can be quite complicated and SAS Technical Report P-222, a paper in the 1994 Northeast SAS Users Group Proceedings, by Alan Dickson entitled "Blind Dates & Other Lapses of Reason: Handling Dates in SAS." We demonstrate some elementary applications of these functions .


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

SAS Programming Topics