BookmarkSubscribeRSS Feed
Sean_OConnor
Fluorite | Level 6

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
Fluorite | Level 6

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-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!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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