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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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