Replacement Variables inside quotes

For questions regarding programming in the EViews programming language.

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

sfawver
Posts: 29
Joined: Wed Aug 25, 2010 9:15 am

Replacement Variables inside quotes

Postby sfawver » Thu May 19, 2011 10:44 am

I've seen posts saying you can't include replacement variables inside quotes. Has anyone figured out a work around for this?

Is this example in the help the work around?

%b = "mom!"
%a = "hi %b"
table(1, 2) = %a
%a = "hi " + %b


This is what I've tried but can't get it to work.

%dir="Copy of 2011Q1"

allmsa.read(t=xls, a1, s=All436areas) "\\Pmi-shares\Risk Management\Economics & Strategy\HPFM\Scott_eviews\"+{%dir}+"\All436areas.xls"

allmsa.read(t=xls, a1, s=All436areas) "\\Pmi-shares\Risk Management\Economics & Strategy\HPFM\Scott_eviews\{%dir}\All436areas.xls"

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

Re: Replacement Variables inside quotes

Postby EViews Gareth » Thu May 19, 2011 11:21 am

First of all, if you're using EViews 7, you should not be using the READ command, rather you should use IMPORT or WFOPEN.

Secondly, in answer to your question, you'll have to create intermediary variables that contain the full path:

Code: Select all

%dir="Copy of 2011Q1"

%path1 = "\\Pmi-shares\Risk Management\Economics & Strategy\HPFM\Scott_eviews\"+{%dir}+"\All436areas.xls"
allmsa.read(t=xls, a1, s=All436areas) %path1

%path2 =  "\\Pmi-shares\Risk Management\Economics & Strategy\HPFM\Scott_eviews\{%dir}\All436areas.xls"
allmsa.read(t=xls, a1, s=All436areas) %path2
Follow us on Twitter @IHSEViews

sfawver
Posts: 29
Joined: Wed Aug 25, 2010 9:15 am

Re: Replacement Variables inside quotes

Postby sfawver » Thu May 19, 2011 12:35 pm

Got it. This works.

The file I'm reading in isn't the workfile. It's a table of MSA codes needed to loop through the regressions.

%dir="Copy of 2011Q1"
%file1="\All436areas.xls"
%file2="\UR_NSA_Forecasts_eq1_2011Q1.xls"
%path="\\Pmi-shares\Risk Management\Economics & Strategy\HPFM\Scott_eviews\"

%fullpath=%path + %dir
%fullfile1=%path + %dir + %file1
%fullfile2=%path + %dir + %file2

allmsa.read(t=xls, a1, s=All436areas) %fullfile1
ur_nsaf_vector.write(t=xls) %fullfile2

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

Replacement Variables inside quotes

Postby EViews Gareth » Thu May 19, 2011 12:37 pm

You should still use WFOPEN or IMPORT.
Follow us on Twitter @IHSEViews

sfawver
Posts: 29
Joined: Wed Aug 25, 2010 9:15 am

Re: Replacement Variables inside quotes

Postby sfawver » Thu May 19, 2011 1:57 pm

I do see wfopen is faster but it creates a new workfile. Is there a way to use wfopen to create a series in an existing workfile?

this is what i'm using
allmsa.read(t=xls, a1, s=All436areas) %fullfile1

this creates a new workfile and i can't figure out how to name the series
wfopen(wf=allmsa page=All436areas name=allmsa) %fullfile1

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

Re: Replacement Variables inside quotes

Postby EViews Gareth » Thu May 19, 2011 2:01 pm

IMPORT
Follow us on Twitter @IHSEViews

bcchen
Posts: 31
Joined: Tue May 02, 2017 8:34 am

Re: Replacement Variables inside quotes

Postby bcchen » Mon Jun 19, 2017 10:03 am

Hello, I am trying to loop inside a location path as shown in the codes below.

Code: Select all

for %quarter 07q4 08q1 08q2

%file1="c:\users\bc03760\desktop\i-common field building\datarows\quarter workfiles\common field round\common filed round 2 apploan-acct attribute\commonfiled_"+{%quarter}+"apploan_2.wf1"

wfopen %file1
next


But it doesn't work. EViews pop up error as :
%FILE1 is not defined or is an illegal command in
"%FILE1="C:\USERS\BC03760\DESKTOP\I-COMMON FIELD
BUILDING\DATAROWS\QUARTER WORKFILES\COMMON
FIELD ROUND\COMMON FILED ROUND 2 APPLOAN-ACCT
ATTRIBUTE\COMMONFILED_"+07Q4+"APPLOAN_2.WF1"".


Can you tell me how to fix it? Thanks!

Best,
BC

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

Re: Replacement Variables inside quotes

Postby EViews Gareth » Mon Jun 19, 2017 10:18 am

Remove the braces from around %quarter
Follow us on Twitter @IHSEViews

bcchen
Posts: 31
Joined: Tue May 02, 2017 8:34 am

Re: Replacement Variables inside quotes

Postby bcchen » Mon Jun 19, 2017 10:54 am

oh yes! Got it worked now!
Thank you Gareth!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 64 guests