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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 1510 views
  • 2 likes
  • 4 in conversation