Dear All,
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...
BR
Lorenzo!!!
format var3 datetime22.3;
var3 = var1 + input(var2,time5.);
So you want to merge based on the datepart only? Then you can use
on put(datepart(dt22var),date9.)=substr(textdate,1,9)
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.
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.
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!!
If var3 is to be text
var3=put(datepart(var1,date9.)||":"||strip(var2)||"00.000";
If num
var3=input(put(datepart(var1,date9.)||":"||strip(var2)||"00.000",datetime22.3);
format var3 datetime22.3;
var3 = var1 + input(var2,time5.);
Thanks to all.
The simplest solution is the right one.
Thank you Kurt!
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)
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.)
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.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.