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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: