A little announcement. A lot to explore.

Happy learning!

Explore lessons, including SAS & R programs and practice data.

Search lessons

Type at least 3 characters to see matching lessons.

Open SAS ↗Open R ↗
← SASnRExtract Day, Month, Year, Weekday from Date

Introduction

  • Clinical reports frequently need pieces of a date — the day, the month, the year, or the name of the weekday — rather than the whole date at once.
  • Typical uses: group by month, band by year of enrolment, flag weekend visits, build custom date strings.
  • SAS offers the date-part functions day(), month(), year(), and weekday() — each takes a SAS date and returns an integer.
  • Tidyverse uses the lubridate package: day(), month(), year(), and wday(), with wday(..., label = TRUE) giving the weekday name.
  • Base R uses format() with %d, %m, %Y to pull out components and weekdays() for the weekday name.
  • This lesson extracts day, month, year, and weekday from a short vector of birth dates so each result is easy to compare.

Extract Day, Month, Year, Weekday from Date