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: 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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1547 views
  • 0 likes
  • 2 in conversation