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.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.