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