12-14-2017 12:12 AM - edited 12-14-2017 12:14 AM
I am new to sas and I am trying to convert a character string which is in ISO8601 to datetime format in sas.
My code looks like this
,input(submitdate,datetime22.9) as Submitdate
submitdate is being pulled from an XML data source so its currently in varchar format
Could any help me with converting the submitdate(which is in iso8601) to datetime? I am new and I only use proc sql; since I have a sql background and still very new to SAS.
12-14-2017 12:29 AM - edited 12-14-2017 12:31 AM
Have you tried this link yet?
You may want to apply one of these informat from the above link:
|Datetime with time zone||YYYY-MM-DDThh:mm:ss.nnnnnn+|-hh:mm||2008-09-15T15:53:00+05:00||E8601DZw.d|
|Read date from a datetime||YYYY-MM-DD||2008-09-15||E8601DNw.|
12-14-2017 12:31 AM
I found that page on a google search, but don't quite understand what I would need to do to convert from ISO8601 varchar to datetime22.9 format in SAS. using the above code.
12-14-2017 12:33 AM
The idea is to apply informat from the page and the informat should convert iso date to a datetime value of sas. Then you apply a datetime format on the numeric datetime value that you derived by applying the informat
12-14-2017 12:37 AM - edited 12-14-2017 12:39 AM
Input ( your_variable, <informat - what variable currently looks like>) as new_variable format=<format - what you want variable to look like>
The INFORMAT is likely one from @novinosrin post and the format is DATETIME20.
The decimal portion of 9 is likely not what you actually want, so I would try datetime20 first.
12-14-2017 01:26 AM - edited 12-14-2017 01:28 AM
input(date, informat=e8601dzw.d) as Date format=datetime20input(date, informat=e8601dzw.d) as Date format=datetime20
e8601dzw.d specify and remove informat=
specifies the width of the input field.
specifies the power of 10 by which to divide the value. If the data contain decimal points, the d value is ignored. This argument is optional.
Specify the informat just like you did earlier with a datetime example
12-14-2017 11:26 AM
example of the date i am trying to convert '2015-12-14T12:00:29.3387979-05:00'
input(submitdate, E8601Dz.) as date format=datetime20.
i tried the above code and i get blanks
12-14-2017 03:34 PM - edited 12-14-2017 06:43 PM
Informats will have a default width if not supplied. In the case of E8601DZ that default is 26. Which for your example is in the middle of the decimal portion of the seconds which means the required part of -05:00 is not seen by the informat. Which will require using the W part of the format.
data junk; x= '2015-12-14T12:00:29.3387979-05:00'; y=input(x,e8601dz33.); format y datetime20.; put y datetime20.; run;
Informats, other thant when used in fixed column input statements, seldom have problems when W is larger than the input string's length.
If you have more decimals in the seconds you may want to use the maximum of W=35 in the informat.
Is your clock actually accurate to the millionth of a second???