BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
WilliamB
Obsidian | Level 7

Hello,

 

I would like to subtract the date of the day 2 weeks.

 

 

% let day =% sysfunc (today () - 14);

 

 

Can you help me?

Thank you

1 ACCEPTED SOLUTION
7 REPLIES 7
sustagens
Pyrite | Level 9
data _null_;
_2_wks_ago=intnx('week',today(),-2);
run;
Kurt_Bremser
Super User

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

sustagens
Pyrite | Level 9
Missed that, I agree. Without the 's' it will subtract two weeks from the date, yes, but it will give the starting day of the week which is the Sunday of that week
WilliamB
Obsidian | Level 7
Thank you very much, how to put it in date9 format.
sustagens
Pyrite | Level 9
%let day=%sysfunc(intnx(week,%sysfunc(today()),-2,s),date9.);
%put &=day;
Kurt_Bremser
Super User

@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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1119 views
  • 0 likes
  • 3 in conversation