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
@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.
Do you want to convert it to a date or datetime value?
the same format I need , but the type should be numeric
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;
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;
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
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.
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
@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.
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!
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.
Ready to level-up your skills? Choose your own adventure.