As the first step in the decommissioning of the site has been converted to read-only mode.

Here are some tips for How to share your SAS knowledge with your professional network.

NWKDOM Function

From sasCommunity
Jump to: navigation, search

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\
description: loop thru months in year listing Nth week and Weekday-th
purpose    : demo of function nwkdom
%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;
*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.));
%mend Which_Day;


--Ronald_J._Fehd macro.maven == the radical programmer 16:12, 18 January 2013 (EST)