Table of Contents
SAS (Statistical Analysis System) is a powerful software used for data analysis and management. One of its useful functions is the ability to retrieve the day of the week from a given date. This can be done by using the WEEKDAY function in SAS, which returns a numeric value representing the day of the week for a specified date. The function takes into account the SAS system option that specifies the first day of the week, making it customizable for different regions and cultures. By utilizing this function, users can easily obtain the day of the week from a given date, saving time and effort in data analysis and decision-making processes.
SAS: Get Day of Week from Date
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 printdata=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 printdata=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.
The following tutorials explain how to perform other common tasks in SAS:
Cite this article
stats writer (2024). How can I get the day of the week from a given date using SAS?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-get-the-day-of-the-week-from-a-given-date-using-sas/
stats writer. "How can I get the day of the week from a given date using SAS?." PSYCHOLOGICAL SCALES, 23 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-get-the-day-of-the-week-from-a-given-date-using-sas/.
stats writer. "How can I get the day of the week from a given date using SAS?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-get-the-day-of-the-week-from-a-given-date-using-sas/.
stats writer (2024) 'How can I get the day of the week from a given date using SAS?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-get-the-day-of-the-week-from-a-given-date-using-sas/.
[1] stats writer, "How can I get the day of the week from a given date using SAS?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can I get the day of the week from a given date using SAS?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
