Hello,
I would like to subtract the date of the day 2 weeks.
% let day =% sysfunc (today () - 14);
Can you help me?
Thank you
As pure macro code:
%let day=%eval(%sysfunc(today()) - 14);
or
%let day=%sysfunc(intnx(week,%sysfunc(today()),-2,s));
data _null_;
_2_wks_ago=intnx('week',today(),-2);
run;
@sustagens wrote:
data _null_; _2_wks_ago=intnx('week',today(),-2); run;
This will not give you the wanted value, run this:
data _null_;
_2_wks_ago=intnx('week',today(),-2);
wanted = today() - 14;
put _all_;
run;
You need to add the 's' modifier to the intnx call.
As pure macro code:
%let day=%eval(%sysfunc(today()) - 14);
or
%let day=%sysfunc(intnx(week,%sysfunc(today()),-2,s));
%let day=%sysfunc(intnx(week,%sysfunc(today()),-2,s),date9.);
%put &=day;
@WilliamB wrote:
Thank you very much, how to put it in date9 format.
Apply the date9. format in the %sysfunc.
But what for? For calculations and comparisons, the raw value is much easier to handle. And for display, there are much better formats like e8601da10. (ISO 8601 date format).
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.