Function nwkdom: N weekday of month :: find date of WDth weekday in Wth week of month
Q: How to find the dates of the first Monday in the second week of every month in the year? A: Use the nwkdom: Nth Weekday Day of Month function in a loop.
This program shows both a data step and a macro that generate a list of the Ith weekday of the Jth week of the 12 months in a year.
/*name: ...\SASpapers-active\00-2013-macro-datetime-loops\sas\ N-week-day-of-month-SS-check.sas description: loop thru months in year listing Nth week and Weekday-th purpose : demo of function nwkdom n.week.day.of.month ****/ %Let Year = 2013; %Let Nth_week = 2;*in (1:5); %Let Weekday = 1;*in (1:7 == (Sunday:Saturday); Data _Null_; retain year &Year n &Nth_week weekday &Weekday; *do year = 2013 to 2014; do month = 1 to 12; ThisDay = NWKDOM(n, weekday, month, year); *put ThisDay best.; put ThisDay weekdate29.; end; put; * end; stop; run; *option symbolgen; %Macro Which_day(n=1,weekday=1,month=1,year_start=2013,year_end=2013); %do year = &Year_start %to &Year_end; %do month = 1 %to 12; %Let Day = %sysfunc(NWKDOM(&n, &weekday, &month, &year)); %put Day: %sysfunc(putn(&Day,weekdate29.)); %end; %put; %end; %mend Which_Day; %Which_day()
--Ronald_J._Fehd macro.maven == the radical programmer 16:12, 18 January 2013 (EST)