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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 368 views
  • 0 likes
  • 2 in conversation