WEEKDAY Function in SAS (Calculate 4 days of week)

The WEEKDAY function produces an integer that represents the day of the week, where 1 = Sunday, 2 = Monday, …, 7 = Saturday.

Basic Syntax:

				WEEKDAY(<date>);
			

Here is the complete table of how the weekday function returns the values.

Sunday1
Monday2
Tuesday3
Wednesday4
Thursday5
Friday6
Saturday7

Day of the Week

The first step is to create a dataset where you have information about the day of the week. To know today’s day, you have to pass today’s date in the WEEKDAY function.

Let’s assume today’s date is: Monday, January 20, 2025. Use DOWNAME. format to print week day in plain English. This is how you can calculate day of the week

				data _null_;
	today='20JAN2025'd;
	weekdays=weekday(today); /* it's a monday */
	wday=put(today, dowName.);
	put weekdays= wday=;
run;

			
Output: weekdays=2 wday=Monday

You can put this code in the do loop iterating for the next 7 days to calculate days for the entire week.

				data _null_;
	today='20JAN2025'd; /* it's a monday */
	
	do i=0 to 6;
		weekdays=weekday(today+i);
		wday=put(today +i, dowName.);
		put weekdays=wday=;
	end;
run;
			

Output:

print weekday in SAS

WEEKDAY<daysW> in INTCK Function:

The INTCK function in SAS returns the number of interval boundaries that lie between two SAS dates, times, or timestamp values.

In the INTCK function there is an option to set “interval”. It can be year, month, week, or weekday. Since we are discussing the WEEKDAY function already, let’s look at how it’s being used in the INTCK function as an interval parameter.

You get the option to set the weekdays and weekends by specifying correct WEEKDAY<daysW> intervals. Here also applies the above table (WEEKDAY function) which produces an integer that represents the day of the week, where 1 = Sunday, 2 = Monday, …, 7 = Saturday.

INTCK WEEKDAY Examples:

  • WEEKDAY1W: Six-day week with Sunday as a weekend day
  • WEEKDAY2W: Six-day week with Monday as a weekend day
  • WEEKDAY17W: Five-day week with Sunday and Saturday are weekend days
  • WEEKDAY56W: Five-day week with Thursday and Friday are weekend days
  • WEEKDAY: Five-day week with Sunday and Saturday are weekend days. The WEEKDAY and WEEKDAY17W are the same interval.

Simple Weekday example :

				
data intck_weekdays_demo;
	format date1 date2 date9.;
	date1='01MAR2025'd;
	date2='28MAR2025'd;

    /* by default Saturday and Sunday are weekends */
	weekdays=intck ('WEEKDAY', date1, date2); 

proc print data=intck_weekdays_demo;
run;

			
Calculate Weekdays in SAS

WEEKDAY INTCK function Examples:

The below example that demonstrate how you can set any week day as a weekend and calculate the intervals between the two dates.

It’s useful to calculate working hours, overtime, especially for those organisations that follow different weekends than saturday, sunday. 

				data intck_weekdays_demo;
	format date1 date2 date9.;
	date1='01MAR2025'd;
	date2='28MAR2025'd;

	/* saturday and sunday are weekend days */
	weekdays=intck('WEEKDAY', date1, date2);

	/* sunday as a weekend day */
	weekdays_1w=intck('WEEKDAY1W', date1, date2);

	/* monday as a weekend day */
	weekdays_2w=intck('WEEKDAY2W', date1, date2);

	/* saturday and sunday are weekend days */
	weekdays_17w=intck('WEEKDAY17W', date1, date2);

	/* thursday and friday are weekend days */
	weekdays_56w=intck('WEEKDAY56W', date1, date2);

proc print data=intck_weekdays_demo;
run;

			
Calculate 5 days of Week in SAS

How to calculate 4 days of week in SAS?

You can set weekend days from the week days using the WEEKDAY interval in the format WEEKDAY(daysW) in the INTCK function that calculates the difference between the dates.

Example: Calculate  the days between 01Mar2025 and 28Mar2025 according to the following situations:

  • Five Days a Week: Set Saturday, and Sunday as weekend days. 
  • Four Days a Week: Set Friday, Saturday, and Sunday as weekend days.
				data intck_weekdays_demo;
	format date1 date2 date9.;
	date1='01MAR2025'd;
	date2='28MAR2025'd;
	fiveDaysWeek=intck ('WEEKDAY', date1, date2); /* by default saturday and sunday are weekends */
	fourDaysWeek=intck ('WEEKDAY167W', date1, date2); /* friday, saturday, and sunday are weekends */

proc print data=intck_weekdays_demo;
run;
			
Calculate 4 days of Week in SAS

FAQ

What is WEEKDAY function in SAS?

The WEEKDAY function produces an integer that represents the day of the week, where 1 = Sunday, 2 = Monday, …, 7 = Saturday.

Syntax:

WEEKDAY(<date>);

How to calculate 4 days a week in SAS?

You can set weekend days from any week days using the WEEKDAY interval in the format WEEKDAY(daysW) in the INTCK function that calculates the difference between the dates.

  • fiveDaysWeek=intck (‘WEEKDAY’, date1, date2); /* by default saturday and sunday are weekends */
  • fourDaysWeek=intck (‘WEEKDAY167W’, date1, date2); /* friday, saturday, and sunday are weekends */