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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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