The SAS Output Delivery System and reporting techniques

concatenating two separate fields (date and time) into one datetime field

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

concatenating two separate fields (date and time) into one datetime field

I have two separate fields - one a date and one a time - that I need to concatenate together into one long datetime field.

Date field is a numeric field, currently in the YYYY-MM-DD format (2014-07-24 for example) and the time field is numeric in the HH:MMSmiley FrustratedS format (9:23:00 or 11:35:00 for example - the leading 0 is not there for half of the time).

I need to get these two separate fields into a format that looks like:  01NOV13:09:23:00 - the date has a length of 7, the time has a length of 8 and there is a colon between them.

I tried formatting both fields, then concatenating, then formatting the concatenated field, and no such luck.

Thanks!


Accepted Solutions
Solution
‎09-06-2017 01:52 PM
Respected Advisor
Posts: 3,167

Re: concatenating two separate fields (date and time) into one datetime field

Posted in reply to DianeAnna

Since your date and time are numeric, another option is to use DHMS function.

newdtm=dhms(date, 0,0,time);
Haikuo

View solution in original post


All Replies
Super User
Super User
Posts: 9,416

Re: concatenating two separate fields (date and time) into one datetime field

Posted in reply to DianeAnna

Hi,

attrib newdate format=datetime15.;

newdate=input(put(date,date7.)||put(time,hhmmss.),datetime.);

New Contributor
Posts: 2

Re: concatenating two separate fields (date and time) into one datetime field

Great - that worked, except that SAS couldn't find the hhmmss format - I changed it to hhmm8. and then it worked like a charm.

I didn't even think about the attrib - have rarely used it.

Thanks!

Solution
‎09-06-2017 01:52 PM
Respected Advisor
Posts: 3,167

Re: concatenating two separate fields (date and time) into one datetime field

Posted in reply to DianeAnna

Since your date and time are numeric, another option is to use DHMS function.

newdtm=dhms(date, 0,0,time);
Haikuo
🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 20318 views
  • 6 likes
  • 3 in conversation