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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.