Rename all series in a database based on Excel sheet

For questions regarding programming in the EViews programming language.

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

chester
Posts: 44
Joined: Thu May 12, 2016 11:14 am

Rename all series in a database based on Excel sheet

Postby chester » Tue Nov 15, 2016 1:55 pm

I have an EViews database with 1803 series and all of them need to be renamed.
I have an Excel sheet that outlines all the old series names and maps them to new names.
How can I write a program that loops and renames series in the EViews database if they match the name in the Excel sheet?

EViews Jason
EViews Developer
Posts: 870
Joined: Tue Sep 16, 2008 3:50 pm

Re: Rename all series in a database based on Excel sheet

Postby EViews Jason » Tue Nov 15, 2016 4:53 pm

Assuming you have an excel file containing 2 columns of names, try:

Code: Select all

create u 10000 'create a workfile big enough to hold all the renames 'read in the excel and create two alpha series named 'oldnames' and 'newnames' import foo.xlsx range=Sheet1 colhead=0 namepos=all na="#N/A" names=(oldnames, newnames) @smpl @all dbopen test ' open the database with the objects you wish to rename !namestochange = @ilast(oldnames) ' number of renames svector new = @convert(newnames) svector old = @convert(oldnames) ' loop through one row at a time for !i=1 to !namestochange+1 %oldseriesname = old(!i) %newseriesname = new(!i) rename test::{%oldseriesname} test::{%newseriesname} next

chester
Posts: 44
Joined: Thu May 12, 2016 11:14 am

Re: Rename all series in a database based on Excel sheet

Postby chester » Wed Nov 16, 2016 9:26 am

Assuming you have an excel file containing 2 columns of names, try:

Code: Select all

create u 10000 'create a workfile big enough to hold all the renames 'read in the excel and create two alpha series named 'oldnames' and 'newnames' import foo.xlsx range=Sheet1 colhead=0 namepos=all na="#N/A" names=(oldnames, newnames) @smpl @all dbopen test ' open the database with the objects you wish to rename !namestochange = @ilast(oldnames) ' number of renames svector new = @convert(newnames) svector old = @convert(oldnames) ' loop through one row at a time for !i=1 to !namestochange+1 %oldseriesname = old(!i) %newseriesname = new(!i) rename test::{%oldseriesname} test::{%newseriesname} next
That looks great! I'm testing that out right now.
I have a select few series that are actually named the same (so don't need to be renamed).
I want to add an 'IF' statement right before the 'rename' line that basically says

Code: Select all

if main_econ::{%oldseriesname} = main_econ::{%newseriesname} then 'Move to next row else rename main_econ::{%oldseriesname} main_econ::{%newseriesname} endif next
How can I say "do nothing and move to next row"?

EViews Jason
EViews Developer
Posts: 870
Joined: Tue Sep 16, 2008 3:50 pm

Re: Rename all series in a database based on Excel sheet

Postby EViews Jason » Wed Nov 16, 2016 10:34 am

The cleanest thing to do is to just handle the 'not' case

Code: Select all

if main_econ::{%oldseriesname} <> main_econ::{%newseriesname} then rename main_econ::{%oldseriesname} main_econ::{%newseriesname} endif

chester
Posts: 44
Joined: Thu May 12, 2016 11:14 am

Re: Rename all series in a database based on Excel sheet

Postby chester » Wed Nov 16, 2016 1:45 pm

The cleanest thing to do is to just handle the 'not' case

Code: Select all

if main_econ::{%oldseriesname} <> main_econ::{%newseriesname} then rename main_econ::{%oldseriesname} main_econ::{%newseriesname} endif
Thank you Jason. Thank worked wonderfully.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests