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
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
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.
Remove the M, and use the yymmn informat:
data test;
x1 = input(compress('2010M01','M'),yymmn6.);
format x1 yymmddd10.;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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 save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.