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-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

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