I have a datetime character variable which i am converting to date9. but for few obs seconds are missing
ldt atd
2018-12-13T10:30:00 13DEC2018
2018-12-10T09:40 .
I use the this code but it makes the second observation mentioned above as missing
input(ldt, anydtdtm.) as atd format=dtdate9.
is there any way i can make ldt =2018-12-10T09:40 as 2018-12-10T09:40:00
Please suggest
If you want it to be a date variable, simply extract the date part of the character variable and convert like this
data have;
ldt="2018-12-13T10:30:00";output;
ldt="2018-12-10T09:40";output;
run;
data want;
set have;
Adt=input(substr(ldt, 1, 10), yymmdd10.);
format Adt date9.;
run;
Just to be clear, do you want Adt to be a datetime variable or a date variable?
If you want it to be a date variable, simply extract the date part of the character variable and convert like this
data have;
ldt="2018-12-13T10:30:00";output;
ldt="2018-12-10T09:40";output;
run;
data want;
set have;
Adt=input(substr(ldt, 1, 10), yymmdd10.);
format Adt date9.;
run;
No need to extract the chars as th very informat's instructions yymmdd10. will read the non standard char date upto 10 chars and convert to a sas date.
So just apply the informat-->
data have;
ldt="2018-12-13T10:30:00";output;
ldt="2018-12-10T09:40";output;
run;
data want;
set have;
Adt=input(ldt, yymmdd10.);
format Adt date9.;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.