BookmarkSubscribeRSS Feed
robertrao
Quartz | Level 8

Hello,

 

I have two seperate fields for date and time. I want to combine them to use for sorting purposes.

The time begins with SQLs start date as shown (01JAN1900) in the time coloumn.

 

SQL_DATE                                      MILITARY_TIME                  Identifier       WANT (datetime)

11DEC2021:00:00:00       01JAN1900:16:56:00:000            ID1                    11DEC2021:16:56:00

11DEC2021:00:00:00       01JAN1900:23:46:00:000          ID1                       11DEC2021:24:36:00

 

Thank you

 

 

 

2 REPLIES 2
PaigeMiller
Diamond | Level 26
datetime=dhms(datepart(sql_date),hour(timepart(military_time)),minute(timepart(military_time)),0);

 

 

Alternative:

 

datetime2=sql_date+(military_time-'01JAN1900:00:00:00'dt);

 

--
Paige Miller
Tom
Super User Tom
Super User

Use the DHMS() function.  Pass the DATE from the one DATETIME value as the DAYS argument and the TIME from the other DATETIME value as the SECONDS value.

 

want=dhms(datepart(SQL_DATE),0,0,timepart(MILITARY_TIME));

Make sure to attach a datetime type format to the new WANT variable so the values print in the way humans will recognize as datetime values.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 2 replies
  • 323 views
  • 1 like
  • 3 in conversation