BookmarkSubscribeRSS Feed
Sean_OConnor
Obsidian | Level 7

Folks,

 

I have a String variable in the following format - 2010M01.

 

I would like to convert it to a sas date variable.

 

Any help would be great.

 

Kind regards,

 

Sean 

4 REPLIES 4
Sean_OConnor
Obsidian | Level 7

Hi RV9,

 

I'm still running into some trouble on this.

 

I've attached a sample of code as an example;

 

MONTH
2010M01
2010M02
2010M03
2014M01
2010M01
2016M01
2010M01
2018M12
FreelanceReinh
Jade | Level 19

Hi @Sean_OConnor,

 

It's a bit odd that there is a SAS format to write such values (see link provided by RW9), but no informat counterpart. The YYMMN. informat comes close, but requires us to remove the "M":

data test;
m='2010M01';
d=input(compress(m,'M'),yymmn6.);
format d date9.;
run;

proc print data=test;
run;

Note that the resulting date value defaults to the first day of the month.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1430 views
  • 2 likes
  • 4 in conversation