☑ This topic is solved.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 07-28-2022 02:21 AM
(1485 views)
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;
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data test; a='2021-12-01 21:56:59.0000000'; d=input(scan(a,1,' '),yymmdd10.); format d date9.; run;
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data test; a='2021-12-01 21:56:59.0000000'; d=input(scan(a,1,' '),yymmdd10.); format d date9.; run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.