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

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:MM:SS 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!

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

attrib newdate format=datetime15.;

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

DianeAnna
Calcite | Level 5

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!

Haikuo
Onyx | Level 15

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

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 43472 views
  • 8 likes
  • 3 in conversation