BookmarkSubscribeRSS Feed
gor1707
Calcite | Level 5

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?

4 REPLIES 4
Reeza
Super User

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?


 

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Reeza
Super User
Correct, but same issue if doing it manually.
ballardw
Super User

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.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

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. 

Register now!

How to Concatenate Values

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 132 views
  • 0 likes
  • 4 in conversation