DATA Step, Macro, Functions and more

extracting specific date/time information from date variable

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

extracting specific date/time information from date variable

Good day: 

I have 2 datetime variables (in datetime20 format). I would like to extract the date from the first datetime variable and the time from the second datetime variable and combine these extracted portions to form a third datetime variable. Is there a simple way to do this is SAS?


Accepted Solutions
Solution
‎11-02-2011 09:28 AM
Super User
Super User
Posts: 7,039

extracting specific date/time information from date variable

You will want to use the DATEPART, TIMEPART, and DHMS functions.

datetm3 = dhms(datepart(datetm1),0,0,timepart(datetm2));

View solution in original post


All Replies
Solution
‎11-02-2011 09:28 AM
Super User
Super User
Posts: 7,039

extracting specific date/time information from date variable

You will want to use the DATEPART, TIMEPART, and DHMS functions.

datetm3 = dhms(datepart(datetm1),0,0,timepart(datetm2));

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 130 views
  • 0 likes
  • 2 in conversation