Hi
I have a dataset where there are date and time variables. Date is in yyyy-mm-dd format and time is time5. format. Both are text varaibles.
I need to create a date time variable with iso8601 format. Some of the time values are missing.
I need a result with this condition:
if time is missing, then datetime variable should have only date part.
later I need to convert this datetime variable into Numeric value.
for example:
vsdat vstim
2018/01/19
2017/12/22 10:53
thanks.
where vstim is blank.
@rashmirao99 If your vsdat variable and time vstim are numeric, I'd suggest to keep the new variable as a datetime variable substituting 0 in place of missing and combine the two variables using dhms function. This will help in maintaining consistency in my opinion.
One way to go:
data have;
infile datalines dlm=' ' truncover;
input vsdat $10. vstim $5.;
datalines;
2018/01/19
2017/12/22 10:53
;
run;
data want;
set have;
format dttm B8601DT.;
dttm=input(catx(' ',vsdat,vstim),anydtdtm.);
run;
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 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.