Manipulating alpha series

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

javiersan
Posts: 184
Joined: Mon Jan 19, 2009 8:18 am

Manipulating alpha series

Postby javiersan » Tue Jun 22, 2010 8:07 am

Hi,

I have an alpha series contaning date strings which has a mixe of formats and Eviews is unable to read it as a date identifier. Some of the date formats are dd/mm/yyyy and some are yyyy-dd-mm. I want to convert the ones with format yyyy-dd-mm to dd/mm/yyyy.

I have done something like:

Code: Select all

alpha temp=@wreplace(date,"*-*","*##*") series date_len=@len(temp) alpha date_mod=@mid(date,6,2)+"/"+@right(date,2)+"/"+@left(date,4) alpha date_ok=@recode(date_len>10,date_mod,date)
where date_ok has the alpha series with the appropriate format but the codes is a bit convoluted. Do you have any ideas for a better code?

Thanks,

Javier

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13603
Joined: Tue Sep 16, 2008 5:38 pm

Re: Manipulating alpha series

Postby EViews Gareth » Tue Jun 22, 2010 8:23 am

Code: Select all

alpha date_ok = @datestr(@recode(@instr(date,"/")=3,@dateval(date,"dd/mm/yyyy"), @dateval(date,"yyyy-mm-dd")),"dd/mm/yyyy")

javiersan
Posts: 184
Joined: Mon Jan 19, 2009 8:18 am

Re: Manipulating alpha series

Postby javiersan » Tue Jun 22, 2010 8:45 am

Thanks!

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13603
Joined: Tue Sep 16, 2008 5:38 pm

Re: Manipulating alpha series

Postby EViews Gareth » Tue Jun 22, 2010 9:02 am

If the months aren't formatted to be two digits rather than one (i.e. March is just 3, not 03), then you could change the code to be:

Code: Select all

alpha date_ok = @datestr(@recode(@instr(date,"/")>0,@dateval(date,"dd/mm/yyyy"), @dateval(date,"yyyy-mm-dd")),"dd/mm/yyyy")


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests