02-05-2015 08:56 AM
I have a dataset containing a variable DATETIME22.3 with only the date part.
I have a variable $15. with the time part (like 10:00).
How can I combine these two variables in a single Datetime variable?
Thank you for any help...
02-05-2015 10:19 AM
02-05-2015 09:17 AM
So you want to merge based on the datepart only? Then you can use
Assuming of course both use date9. style format.
So basically just put the datepart into the same format as your text and compare, or convert the text one to number and compare datepart with datepart.
02-05-2015 09:22 AM
How can a datetime variable have only a date part?
It may only show the date but it should have a time part as well.
To create a datetime variable use the dhms() function.
Assuming it's actually a date:
new_var=dhms(date_var, hour(time_var), minute(time_var), second(time_var));
If its not a date and is a date time var you can use datepart() function to get the date portion only.
02-05-2015 10:06 AM
You are right.
In the variable DATETIME22.3 you have only the date set, the time part is 00:00:00.
I want to obtain something like this:
Var1 DATETIME22.3 is 22JAN2012:00:00:00.000
Var2 Char(15) is 10:00
Var3 DATETIME22.3 that will be Var1 and var2 combined so 22JAN2012:10:00:00.000
Thank you for any help!!
02-05-2015 10:19 AM
02-05-2015 10:04 AM
Convert the time value in the character variable into a real time value (like newval=input(oldval,time8.)
Then you just add the time value (which is seconds after midnight) to the datetime value (which is seconds after 01jan1960:00:00:00)
02-05-2015 10:24 AM
We probably need more information to give you precise answer, but my assumption is:
" variable DATETIME22.3 with only the date part." meaning something like this: "01JAN2015 00:00:00"dt, the time part is always zero., but the variable is numeric.
if this is the case, then you can go either of the following ways:
new_var=dhms(datepart(date_var), 0, 0, input(time_var, time15.));
2. new_var=input(catx(' ', put(datepart(date_var),date9.),time_var), anydtdtm23.)
Need further help from the community? Please ask a new question.