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?
Rename all series in a database based on Excel sheet
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
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
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
That looks great! I'm testing that out right now.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
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
-
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
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}
endifRe: Rename all series in a database based on Excel sheet
Thank you Jason. Thank worked wonderfully.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
Who is online
Users browsing this forum: No registered users and 1 guest
