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).
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.