Reputation: 644
I have a text-file with a date that I would like to convert into a SAS date. The dates look like this
2014-12-14T07:04:33Z
2014-12-14T07:04:33Z
2014-12-14T07:04:33Z
2014-12-14T07:04:33Z
2014-12-14T07:04:33Z
I know that if the date looked like date_in_string = '05May2013', then I could
input(date_in_string,date9.);
But, I have characters inside the string, and I have not been able to find any suitable formats.
Upvotes: 2
Views: 263
Reputation: 63424
IS8601DZ.
is the correct informat for that datetime, as that is an ISO 8601 datetime format with a timezone.
data test;
input dt IS8601DZ.;
format dt datetime17.;
datalines;
2014-12-14T07:04:33Z
2014-12-14T07:04:33Z
2014-12-14T07:04:33Z
2014-12-14T07:04:33Z
2014-12-14T07:04:33Z
;;;;
run;
To convert to a date-only you can read it in then use DATEPART, or you can use YYMMDD10. to read it in (remember, SAS will happily truncate it for you and ignore the junk at the end - as long as your MM/DD are zero padded). If they're not zero padded you have to parse it in some other fashion.
data test;
input dt YYMMDD10.;
format dt date9.;
datalines;
2014-12-14T07:04:33Z
2014-12-14T07:04:33Z
2014-12-14T07:04:33Z
2014-12-14T07:04:33Z
2014-12-14T07:04:33Z
;;;;
run;
Upvotes: 6