09-25-2017 10:49 AM
I need to program a macro variable which returns the last Saturday of today(). Please see below what I have so far. I’m having a trouble nailing down the syntax.
%let today=%sysfunc(today()); %let sat =%sysfunc(intnx(weekday /*Is weekday the correct intnx option*/,(&today),/*NOT SURE what value to put here*/),date9.); %put &sat ;
09-25-2017 10:59 AM
%let last_sat=%sysfunc(intnx(week.7,%sysfunc(today()),0,b),date9.); %put last_sat=&last_sat ;
09-25-2017 11:16 AM - edited 09-25-2017 11:17 AM
Before engaging in macro programming, solve your issue with a data step first.
Important to know: weekday() returns 1 for Sunday (2 for Monday, and so on), so subtracting the weekday() result from a SAS date value will give you the immediately previous Saturday. Keep in mind that SAS date values are just a count of days from a given starting date.
data _null_; sat = today() - weekday(today()); put sat=; put sat= date9.; run;
Note how the raw value of sat looks.
Now lets put that logic into a macro statement:
%let sat=%eval(%sysfunc(today()) - %sysfunc(weekday(%sysfunc(today())))); %put sat=&sat;
And you'll get the same (technical) result.