For example i have dates in character such as "01-JUN-2021", "05MAY2022", "01-11-2020", "12/12/2022", how can i know in which format they are, or what delimiter they have for converting to iso8601?
Try using ANYDTDTE so SAS will read it in automatically.
https://documentation.sas.com/doc/en/vdmmlcdc/8.1/leforinforref/n04jh1fkv5c8zan14fhqcby7jsu4.htm
@gor1707 wrote:
For example i have dates in character such as "01-JUN-2021", "05MAY2022", "01-11-2020", "12/12/2022", how can i know in which format they are, or what delimiter they have for converting to iso8601?
One of the problems when you get dates like "01-11-2020" is that you can't know, and we can't know, whether this is January 11, 2020 or November 1, 2020. ANYDTDTE will convert them to actual SAS dates, but there's no guarantee that it will pick January 11, 2020 or November 1, 2020 properly. Unless you can go back and ask the providers of the data what "01-11-2020" means (perhaps they have documentation), this is an unsolvable problem.
Read character data into a SAS date (or time or datetime) value with an appropriate Informat. Assign the desired ISO format to that variable.
The issue can be determining the proper informat because there are so many possibilities. Pray that at least the years are all 4-digits or the issue can get pretty ugly.
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.