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.

AI Navigator GIF.gif


Navigate AI governance with SAS tools for compliance and ethical AI practices. Try SAS Ai Navigator for free for the first six months.

Check it out on Microsoft Marketplace →

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