hi
i have a date and time data in character format how can i convert them to numeric in datastep
data sample;
input datetime $ 16.;
cards;
01-10-2018t10:15
01-10-2018t10:20
01-10-2018t10:20
;
date should be in date9 format and time should be in time5.
please help me friend..
data sample;
input datetime $ 16.;
date = input(substr(datetime,1,10),ddmmyy10.);
time = input(substr(datetime,12,5),time5.);
format date date9. time time5.;
cards;
01-10-2018t10:15
01-10-2018t10:20
01-10-2018t10:20
;
run;
Sorry, why do you have datetimes in that format in the first place. It looks to me like a data error. The T indicates that its an ISO date, however the format of ISOdates are:
YYYY-MM-DDTHH:MM
(Plus of course all the seconds, time zone etc.).
Now your data has that kind of form but is all the wrong way round. Go back to source and get it fixed. This should be in your data transfer agreement/spec, otherwise you could be in all kinds of difficulties, e.g.
01-10-2018t10:15
10-01-2018t10:20
Are they both 01Oct, or is the second 10Jan? Proper data formatting is key foundation in programming.
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.