Concatenating Date and Time in PROC SQL

Accepted Solution Solved
Reply
Contributor
Posts: 37
Accepted Solution

Concatenating Date and Time in PROC SQL

Date is formatted as such: 25JAN2018

and Time is formatted as such: 16:18:23

 

Trying to return a new field to where datetime is returned: 25JAN2018 16:18:23

 

I tried a cast function on both fields and attempted to combine and no such luck.  Is there anyway to do this in PROC SQL?

 

Thanks in advance.

 

 


Accepted Solutions
Solution
‎02-23-2018 09:39 AM
Super User
Super User
Posts: 8,111

Re: Concatenating Date and Time in PROC SQL

Posted in reply to PhatRam33

PhatRam33 wrote:

It is in SQL pass-through.  The date field is in date9 format I believe and the time field is in time8 format if that helps.


In that case you need to know which flavor of SQL your foreign database is using and find the appropriate command in that language.  Are you using Oracle? Teradata? Redshift? Microsoft SQL Server?  IBM ?? etc.

View solution in original post


All Replies
Super User
Posts: 23,724

Re: Concatenating Date and Time in PROC SQL

Posted in reply to PhatRam33

CAST() is not a SAS function, are you using SQL Pass through and are the fields SAS dates or character variables?

 

If it's SAS dates/times you can use the DHMS() function to compile the date and format as desired.

 


PhatRam33 wrote:

Date is formatted as such: 25JAN2018

and Time is formatted as such: 16:18:23

 

Trying to return a new field to where datetime is returned: 25JAN2018 16:18:23

 

I tried a cast function on both fields and attempted to combine and no such luck.  Is there anyway to do this in PROC SQL?

 

Thanks in advance.

 

 


 

Contributor
Posts: 37

Re: Concatenating Date and Time in PROC SQL

It is in SQL pass-through.  The date field is in date9 format I believe and the time field is in time8 format if that helps.

Solution
‎02-23-2018 09:39 AM
Super User
Super User
Posts: 8,111

Re: Concatenating Date and Time in PROC SQL

Posted in reply to PhatRam33

PhatRam33 wrote:

It is in SQL pass-through.  The date field is in date9 format I believe and the time field is in time8 format if that helps.


In that case you need to know which flavor of SQL your foreign database is using and find the appropriate command in that language.  Are you using Oracle? Teradata? Redshift? Microsoft SQL Server?  IBM ?? etc.

Contributor
Posts: 37

Re: Concatenating Date and Time in PROC SQL

[ Edited ]

The language for the database is IBM DB2 I believe.

Contributor
Posts: 37

Re: Concatenating Date and Time in PROC SQL

I figured it out.  Once I found out the language of the database, the wheels started turning lol.   Tom I give you credit though I totally missed this key question.

 

Was able to use the timestamp function with success: 

timestamp(CREATE_DT, CREATE_TM) as CREATE_DT_TM

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 364 views
  • 0 likes
  • 3 in conversation