⨳ %d: a handy little macro for dynamic dating ⨳

July 8, 2009

for a little over a year now, i’ve been enjoying a little macro i wrote for writing date values in a variety of formats. the macro also integrates the intnx function (hence the dynamic part). this allows me to easily use dynamic dates in both open and closed code (between and within data/proc steps).

suppose i’ve got a report that needs to be updated monthly using 6 months of data lagged 3 months (i know, contrived example, but stick with me). supposing today is 10SEP2009, i’d need to report on data from FEB-JUN2009. i could do something like this:

title "%d(yymon, interval=month, increment=-8) - %d(yymon, interval=month, increment=-3, alignment=e) Data";
where Month between "%d(interval=month, increment=-8)"d and "%d(interval=month, increment=-3, alignment=e)"d;

the following iterations, i can simply re-run the report to get the appropriate data. no more %let statements!

but what if you want to specify a date? no problem: use the d parameter (the d parameter expects values formatted in date9 style). you can either hard code the date (wha?) or use a macro variable. okay, i lied about the end of %let statement.

looking at the source code, you’ll notice that one line (line 43) does all the heavy lifting. with the bulk of the macro for what i’ll call “self- documentation” (both for developers and end-users).

for example, if i submit %d(HELP); (lines 24-42), the macro writes some basic how-to info in the log. which translates into less time hand-holding assisting others.

additionally, if i submit %d(EDIT); (lines 42-47), the source code is opened in the editor for users to view and (eek) make edits. you’d obviously need to update line 45 with the location of the file on your setup.

there you have it. i’ll see you "%d(interval=month, increment=1)"d.


%d: a handy little macro for dynamic dating - July 8, 2009 -