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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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