Can soomeone help me to convert character datetime value to numeric date? Desired output is '01DEC2021'd which is in date9. format
data test; a='2021-12-01 21:56:59.0000000'; b=input(a,27.); run;
data test; a='2021-12-01 21:56:59.0000000'; d=input(scan(a,1,' '),yymmdd10.); format d date9.; run;
data test; a='2021-12-01 21:56:59.0000000'; d=input(scan(a,1,' '),yymmdd10.); format d date9.; run;
You can apply the YYMMDD10. informat directly, as it will only read the first 10 characters:
data test;
a = '2021-12-01 21:56:59.0000000';
b = input(a,yymmdd10.);
format b yymmdd10.;
run;
To read the whole string as a datetime, use the E8601DT. informat:
data test;
a = '2021-12-01 21:56:59.0000000';
b = input(a,e8601dt26.);
c = datepart(b);
format
b e8601dt26.6
c yymmdd10.
;
run;
I have a lot of files that apparently originate in not-well set up databases where I get date values that come as datetime values like that, some times as many as 30 date fields per record. Every single "time" component is 00:00:00. So using just the date format to read the date part makes lots of sense and I do it in the data step to read the file instead of waiting to fix it later.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.