Hello Team,
I have date in one field and time in another..like shown in different formats. How can i combine both
DATE TIME ID
(DATETIME20. Formt) (DATETIME22.3 FMT)
17DEC2014:00:00:00 01JAN190013:26:00.000 101
26DEC2014:00:00:00 01JAN1900:19:36:00.000 102
WANT: DATE_TIME LIKE SHOWN
DATE_TIME ID
17DEC2014:13:26 101
26DEC2014:19:36 102
Regards
Hi @robertrao,
If both variables are datetimes you can use DATEPART() on the one and TIMEPART() on the other. Now you can combine them with DHMS(). In one line:
datetime=dhms(datepart(date), 0, 0, timepart(time));
Hope this helps,
- Jan.
Hi @robertrao,
If both variables are datetimes you can use DATEPART() on the one and TIMEPART() on the other. Now you can combine them with DHMS(). In one line:
datetime=dhms(datepart(date), 0, 0, timepart(time));
Hope this helps,
- Jan.
datetime=dhms(datepart(date), 0, 0, timepart(time));
The above work pretty well. But I dint find an explanation online as to why the two zeros are being used in between. The documentation didnt explain it either.
Could you please explain ?
Thanks
The doc does explain this kind of use of DHMS() and especially using a time variable for the fourth parameter.
See the online doc of the DHMS function:
DHMS(SAS date, 0, 0, SAS time).
Hope this clears things up a bit,
- Jan.
Also it looks like you have not accepted my solution but instead a quote from it by yourself.
Thanks @robertrao for setting that right.
You may also want to determine what in your process is creating the time variable as a datetime. The earlier in data streams issues like this are corrected the better in the long run.
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!
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.