BookmarkSubscribeRSS Feed
JillChen0131
Fluorite | Level 6

I have some dates in character format:

UN/UNK/2020

14/JUN/2021

UN/APR/2019

I would need to convert them to the format yyyy-mm-dd. If day and month missing, output will be yyyy only, if day missing, output will be yyyy-mm. 

Thanks

 

2 REPLIES 2
ballardw
Super User

By "output" do you mean that you want an actual SAS date that displays that way?

Or another character variable that can't use any of the date functions?

Or a numeric value that is not in any way a date except possibly in the readers mind?

 

SAS date values must have month and day of month component. And a variable can only have one format in effect at any given time. What you request for "g, output will be yyyy only, if day missing, output will be yyyy-mm" is not possible with actual SAS dates.

 

If you want to use any of the functions such as Intck or Intnx for returning date intervals or adjusting dates, then you will have to provide a day of month and month when missing.

The informats that read yyyymm type generally assume the day of the month to be 1.

You would have to decide what makes sense for your purpose what date of the year just the year value would mean.

PaigeMiller
Diamond | Level 26

Question about these type of "dates" where either the day or the month (or both) has been asked and answered many times:

 

https://communities.sas.com/t5/SAS-Programming/convert-to-iso8601-format/m-p/613845

https://communities.sas.com/t5/SAS-Programming/How-to-convert-below-dates-to-as-required-format/m-p/...

https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575008

 

and many other times. Lots of ideas, lots of answers.

--
Paige Miller

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 359 views
  • 2 likes
  • 3 in conversation