BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
noda6003
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Just to be clear, do you want Adt to be a datetime variable or a date variable?

PeterClemmensen
Tourmaline | Level 20

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;
novinosrin
Tourmaline | Level 20

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;

 

 

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 704 views
  • 0 likes
  • 3 in conversation