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

Team,

 

Trying to convert the dates like below to a numeric with the length of 8 , but its not converting right.

value-2019-07-25T 15:35

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

@ambadi007 wrote:

I have ran the code with 

e8601dt20 format

since I am getting the error like width specified for E8601DT is invalid .. so If iam using  e8601dt20 it is coming with extra zero


Note that my code specifically uses a width of 16 for the display format, and it works and does not display the seconds. If you have further problems, please post your code and log.

According to the documentation of the E8601 display format (Maxim 1!), the range for the width is 16 to 26.

View solution in original post

8 REPLIES 8
PeterClemmensen
Tourmaline | Level 20

Do you want to convert it to a date or datetime value?

ambadi007
Quartz | Level 8

the same format I need , but the type should be numeric 

PeterClemmensen
Tourmaline | Level 20

you can convert it to a numeric datetime value like this. Then format to your liking 

 

data test;
    chardt="2019-07-25T 15:35";
    dt=input(chardt, B8601DT.);
run;
Kurt_Bremser
Super User

Since your datetime looks very much like a ISO-standard, I suspect that the blank is not really there, so this will work:

data test;
dt_char = '2019-07-25T15:35';
dt_num = input(dt_char,e8601dt16.);
format dt_num e8601dt16.;
run;

By testing (Maxim 4) I found out that the e8601 informat is tolerant about such blanks anyway:

data test;
dt_char = '2019-07-25T 15:35';
dt_num = input(dt_char,e8601dt20.);
format dt_num e8601dt16.;
run;
ambadi007
Quartz | Level 8

Its coming correctly but now the value showing like 

2019-07-25T 15:35:00

but  I need it like 

2019-07-25T 15:35

how to remove the extra zeros 

Kurt_Bremser
Super User

Then you haven't run my code.

data test;
dt_char = '2019-07-25T 15:35';
dt_num = input(dt_char,e8601dt20.);
format dt_num e8601dt16.;
run;

proc print data=test noobs;
run;

Result:

     dt_char         dt_num

2019-07-25T 15:35    2019-07-25T15:35

As you can see, no blanks and no trailing zeroes with the numeric variable.

ambadi007
Quartz | Level 8

I have ran the code with 

e8601dt20 format

since I am getting the error like width specified for E8601DT is invalid .. so If iam using  e8601dt20 it is coming with extra zero

Kurt_Bremser
Super User

@ambadi007 wrote:

I have ran the code with 

e8601dt20 format

since I am getting the error like width specified for E8601DT is invalid .. so If iam using  e8601dt20 it is coming with extra zero


Note that my code specifically uses a width of 16 for the display format, and it works and does not display the seconds. If you have further problems, please post your code and log.

According to the documentation of the E8601 display format (Maxim 1!), the range for the width is 16 to 26.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 8 replies
  • 2702 views
  • 0 likes
  • 3 in conversation