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).
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: