I'm having issues converting iso8601 date to numeric and back to iso8601. When converting back to iso8601, I'm getting extra 00's in the time component.
Ex: 2019-12-01T16:40 gets converted to numeric,.To reconvert it back I'm getting 2019-12-01T16:40:00
ANy help is apprecited.
Just use proper format lengths:
data want;
input dt :e8601dt17.;
format dt e8601dt17.;
datalines;
2019-12-01T16:40
;
THanks. what if the some dates have seconds like 2019-12-01T16:40:35 and some dont have 2019-12-01T16:40?
Use the longer format.
2019-12-02T16:40 equals 2019-12-01T16:40:00 anyway, so there's no need to mask the seconds. The shorter format is only useful when seconds don't count.
If the date doesnt have seconds ,I dont want to display seconds.
Then you would need to create a custom format with an embedded function that uses the shorter format when there are no seconds (mod(value,60) = 0).
Or if you just need it in a report, conditionally format to a string first.
My VERY STRONG advice: don't do it, it's not worth the effort. If somebody complains, use a LART.
@SASPhile wrote:
If the date doesnt have seconds ,I dont want to display seconds.
Then you need to store that information in another variable. The easiest way is to just keep the original text string. Or you could store the length of the original string.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.