BookmarkSubscribeRSS Feed
yahoo0806
Calcite | Level 5

Hi all,

I'm having a question regarding to converting partial SAS date.

I'm having some incomplete date like 'OCT 2018', this is a character variable and I want to convert it to '2018-10' also a character variable. 

 

I'm thinking to change it to a numeric variable then convert that numeric to character variable. However since it is a partial date, I'm not sure how to do it.

 

Many thanks!

1 REPLY 1
Tom
Super User Tom
Super User

Are you asking for how to convert the specific pattern MONYYYY into YYYY-MM?

If so you might have some success using the ANYDTDTE informat to convert that string to the first day of the month and then use the YYMMD format to generate the wanted string.

 

WANT=put(input(HAVE,anydtdte.),yymmd7.);

But how well it works depends on how messy your strings are.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1585 views
  • 0 likes
  • 2 in conversation