BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
asuman
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

View solution in original post

6 REPLIES 6
Tom
Super User Tom
Super User

@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
Obsidian | Level 7
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
Tom
Super User Tom
Super User

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

asuman
Obsidian | Level 7
Thanks TOM.It's Working
Reeza
Super User

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.

asuman
Obsidian | Level 7
Thank you for making subject line more effective,i will take care this in future.

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!

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
  • 6 replies
  • 4307 views
  • 0 likes
  • 3 in conversation