- Get link
- X
- Other Apps
DEMONSTRATING THE FUNCTIONS YEAR | QTR | MONTH | WEEK | DAY | WEEKDAY
Function: YEAR
Purpose: To extract the year from a SAS date.
Syntax: YEAR(date)
EG1: Year = year(Date1);
Function: QTR
Purpose: To extract the quarter (January–March = 1, April–June = 2, etc.) from a SAS
date.
Syntax: QTR(date)
EG2:Quarter = qtr(Date1);
Function: MONTH
Purpose: To extract the month of the year from a SAS date (1 = January, 2=February,
etc.).
Syntax: MONTH(date)
EG3: Month = month(Date1);
Function: WEEK
Purpose: To extract the week number of the year from a SAS date (the week-number
value is a number from 0 to 53 or 1 to 53, depending on the optional
modifier).
Syntax: WEEK(<date> <,'modifier'>))
EG4: Week = week(Date1);
modifier is an optional argument that determines how the week-number
value is determined. If modifier is omitted, the first Sunday of the year is
week 1. For dates prior to this date, the WEEK function returns a 0. The
various modifiers provide several different methods for computing the value
returned by the WEEK function. Most users will probably want to use this
function without any modifiers.
Function: WEEKDAY
Purpose: To extract the day of the week from a SAS date (1 = Sunday, 2=Monday,
etc.).
Syntax: WEEKDAY(date)
EG5: Day_of_week = weekday(Date1);
Function: DAY
Purpose: To extract the day of the month from a SAS date, a number from 1 to 31.
Syntax: DAY(date)
EG6: Day_of_month = day(Date1);
CODE:
data date_functions;
set dates(drop=Date2);
Year = year(Date1);
Quarter = qtr(Date1);
Month = month(Date1);
Week = week(Date1);
Day_of_month = day(Date1);
Day_of_week = weekday(Date1);
run;
title "Listing of Data Set DATE_FUNCTIONS";
proc print data=date_functions noobs;
run;
HERE DATES DATASET IS IN THIS PAGE:https://sasall4you.blogspot.com/2025/01/70program-to-create-dates-dataset.html
Explanation:
These basic date functions are straightforward. They all take a SAS date as the single
argument and return the year, the quarter, the month, the week, the day of the month, or the
day of the week. Remember that the WEEKDAY function returns the day of the week, while
the DAY function returns the day of the month (it's easy to confuse these two functions).
Listing of Data Set DATE_FUNCTIONS |
Date1 | Year | Quarter | Month | Week | Day_of_month | Day_of_week |
---|---|---|---|---|---|---|
01JAN1960 | 1960 | 1 | 1 | 0 | 1 | 6 |
02MAR1961 | 1961 | 1 | 3 | 9 | 2 | 5 |
25DEC2000 | 2000 | 4 | 12 | 52 | 25 | 2 |
01FEB2002 | 2002 | 1 | 2 | 4 | 1 | 6 |
TRY THIS AND COMMENT ...
--PLEASE FOLLOW THE BLOG FOR MORE UPDATES...
--FOLLOW US IN FACEBOOK SASALL4YOU AND JOIN ...
--JOIN US IN FACEBOOK AND TELEGRAM CHANNEL FOR MORE UPDATES
CLICK HERE: https://t.me/SasAll4You
- Get link
- X
- Other Apps
Comments
Post a Comment