BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
2023newsas
Calcite | Level 5

Hi all,

I am new to SAS, can you please suggest the best way to replace on the year portion of a date with datetime24.3 

Example date in column dd_date is 01OCT2022: 15:00:28.000. I only need to change 2022 to 2020

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Assuming you have a numeric variable named DATETIME_VALUE that contains this date/time value, and you want to subtract two years, the INTNX command will do that. The format is irrelevant; if a variable contains date/time values, this works regardless of the format.

 

data want;
    set have;
    new_value = intnx('dtyear',datetime_value,-2,'s');
    format new_value datetime24.3;
run;

 

 

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Assuming you have a numeric variable named DATETIME_VALUE that contains this date/time value, and you want to subtract two years, the INTNX command will do that. The format is irrelevant; if a variable contains date/time values, this works regardless of the format.

 

data want;
    set have;
    new_value = intnx('dtyear',datetime_value,-2,'s');
    format new_value datetime24.3;
run;

 

 

--
Paige Miller
2023newsas
Calcite | Level 5
Hi there thank you very much!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Discussion stats
  • 2 replies
  • 910 views
  • 0 likes
  • 2 in conversation