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: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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