In a data set we have a column of date in datetime format.
I want to increment the date with 2 months,4 hrs,10 min and 6 second.
Kindly help to write this query.
@asuman wrote:
In a data set we have a column of date in datetime format.
I want to increment the date with 2 months,4 hrs,10 min and 6 second.
Kindly help to write this query.
So you have column with DATETIME (not DATE).
You can use the INTNX() function to increment dates by periods. You will HAVE to use it to increment by MONTH, but since the value is DATETIME you need to use the DTMONTH interval. To increment by time just add the time value since both DATETIME and TIME values are stored as number of seconds.
want=intnx('dtmonth',have,2,'same')+'04:10:06't ;
@asuman wrote:
In a data set we have a column of date in datetime format.
I want to increment the date with 2 months,4 hrs,10 min and 6 second.
Kindly help to write this query.
So you have column with DATETIME (not DATE).
You can use the INTNX() function to increment dates by periods. You will HAVE to use it to increment by MONTH, but since the value is DATETIME you need to use the DTMONTH interval. To increment by time just add the time value since both DATETIME and TIME values are stored as number of seconds.
want=intnx('dtmonth',have,2,'same')+'04:10:06't ;
@asuman wrote:
data b;
y=datetime();
format y datetime21.;
want=intnx('dtmonth',y,2)+'02:10:06't;
format want datetime21.;
run;
results:
y=24JUL2019:21:42:04
want=01SEP2019:02:10:06
it's not the correct answer.Need assistance
If you don't tell INTNX() where in the target period you want it will set it to the BEGINNING of the period.
You want to use SAME, not BEGINNING or END.
I've updated your subject line to be more reflective of your question. Please take the time to add a descriptive subject line in the future.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
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.
Ready to level-up your skills? Choose your own adventure.