sas

Creating a Vertical Calendar


Using SAS, is is it possible to use existing date functions and macros to vertically stretch out a calendar data frame?

For example, I want to make a data frame with columns: day, month, year.

This table should contain all days from Dec-1-1999 to Dec-1-2005. I can do this in other software like Python or Excel - but can it be done in SAS?


Solution

  • It's rare to need this sort of calendar table in SAS, because you can normally use date functions or formats to calculate various date values/formats, instead of storing them in a lookup table.

    That said, it's straight forward to make a table like this, e.g.:

    data mycal ;
      do date="01Jan2024"d to today() ;
        calendar_year=year(date) ;
        calendar_month=month(date) ;
        day=day(date) ;
        dayofweek=weekday(date) ;
        output ;
      end ;
      format date date9. ;
    run ;
    
    proc print ;
    run ;
    

    If you can describe in English the logic for the remaining variables, I'm happy to add them.