Page 1 of 1
Rename all series in a database based on Excel sheet
Posted: Tue Nov 15, 2016 1:55 pm
by chester
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?
Re: Rename all series in a database based on Excel sheet
Posted: Tue Nov 15, 2016 4:53 pm
by EViews Jason
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
Re: Rename all series in a database based on Excel sheet
Posted: Wed Nov 16, 2016 9:26 am
by chester
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"?
Re: Rename all series in a database based on Excel sheet
Posted: Wed Nov 16, 2016 10:34 am
by EViews Jason
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
Re: Rename all series in a database based on Excel sheet
Posted: Wed Nov 16, 2016 1:45 pm
by chester
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.