Hi All,
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.
Thanks!
%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 ;
%let last_sat=%sysfunc(intnx(week.7,%sysfunc(today()),0,b),date9.);
%put last_sat=&last_sat ;
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.