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