BookmarkSubscribeRSS Feed
Pandu2
Obsidian | Level 7
Hi all,

I've a datetime value which is
Date = %sysfunc(datetime(), e8601dt24.3);
output : 2022-01-07T10:38:49.095
I would like to subtract 365 days from Date Variable i.e a year.
The wanted Date Variable should look like this
2021-01-07T10.38.49.095
Can anyone please help me on achieving this. Thanks in advance.
2 REPLIES 2
andreas_lds
Jade | Level 19

Don't apply a format to a date, datetime or time macro-variable if you want to use in calculations.

Try

%let wanted = %sysfunc(intnx(dtyear, %sysfunc(datetime()), -1, s), e8601dt24.3);

or if you need the variable date (bad name for a variable not containing a date, but a datetime-value):

%let date = %sysfunc(datetime());
%let want = %sysfunc(intnx(dtyear, &date., -1, s), e8601dt24.3);
%put &=want;
Pandu2
Obsidian | Level 7
Thank you veryy muchh. This looks good and it is working.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 2 replies
  • 662 views
  • 0 likes
  • 2 in conversation