transform character into date: january 2009 into date

Solved
Occasional Contributor
Posts: 6

transform character into date: january 2009 into date

Hello,

I have a character column with values like:

january 2009

may 2009

i try to transform this column in date and i don't succed. i tried

WORDDATX. , but i have this error:

data test;

xx='jan 2009';

yy='january 2009'; output;

run;

data test;

set test;

date=input(xx,monyy8.);

date_yy=input(yy,WORDDAT18.);

run;

if i have 'jan 2009' is ok, but for "'january 2009' " i don't find the informat.

Can you help me ?

thank you!

Accepted Solutions
Solution
‎07-14-2016 04:23 AM
Super User
Posts: 6,759

Re: transform character into date: january 2009 into date

If the coding for XX is working, convert the YY string to the XX form:

date_yy = input(substr(yy, 1, 3) || scan(yy,2), monyy8.);

Technically, there will be only 7 characters to read, but the statement should work if it's working for XX.

All Replies
Super User
Posts: 6,759

Re: transform character into date: january 2009 into date

In SAS, dates represent a single day.  Do  you want a day that matches the first day of the month?

Occasional Contributor
Posts: 6

Re: transform character into date: january 2009 into date

Yes, the first day of the month i need.

Occasional Contributor
Posts: 6

Re: transform character into date: january 2009 into date

[ Edited ]

january 2009=01 jan 2009

Solution
‎07-14-2016 04:23 AM
Super User
Posts: 6,759

Re: transform character into date: january 2009 into date

If the coding for XX is working, convert the YY string to the XX form:

date_yy = input(substr(yy, 1, 3) || scan(yy,2), monyy8.);

Technically, there will be only 7 characters to read, but the statement should work if it's working for XX.

Super User
Posts: 10,770

Re: transform character into date: january 2009 into date

``````data have;
input d \$40.;
date=input(cats('01',d),anydtdte32.);
format date date9.;
cards;
january 2009
jan 2009
may 2009
;
run;``````
Occasional Contributor
Posts: 6

Re: transform character into date: january 2009 into date

Thank you !!!!

Occasional Contributor
Posts: 6

Re: transform character into date: january 2009 into date

Thank you Ksharp !!!
☑ This topic is solved.