You can use the following functions in SAS to get the day of the week from a date:
The WEEKDAY function returns the day of the week as a number (1, 2, 3, 4, 5, 6, 7).
The PUT function with the DOWNAME format returns the day of the week as a name (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday).
The following example shows how to use each of these functions in practice.
Example: Get Day of Week from Date in SAS
Suppose we have the following dataset in SAS that shows the birth date for seven individuals:
/*create dataset*/
data original_data;
format birth_date date9.;
input birth_date :date9.;
datalines;
01JAN2021
22FEB2022
14MAR2022
29MAY2022
14OCT2023
01NOV2024
26DEC2025
;
run;
/*view dataset*/
proc print data=original_data;
We can use the following code to create a new dataset that contains two new variables that show the day of the week as a number and the day of the week as a name for the birth date of each individual:
/*create new dataset*/
data new_data;
set original_data;
weekday_number = WEEKDAY(birth_date);
weekday_name = put(birth_date, dowName.);
run;
/*view new dataset*/
proc print data=new_data;
The two new variables show the day of the week for each birth date as a number and as a name.
For example:
- January 1st, 2021 is on a Friday, which is the 6th day of the week.
- February 22nd, 2022 is on a Tuesday, which is the 3rd day of the week.
- March 14th, 2022 is on a Monday, which is the 2nd day of the week.
And so on.
Additional Resources
The following tutorials explain how to perform other common tasks in SAS:
How to Use DAY, MONTH, and YEAR Functions in SAS
How to Convert Datetime to Date in SAS
How to Add Days to Date in SAS