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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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