Series Name Challenge ("_" Starting Character Issue)
Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt
Series Name Challenge ("_" Starting Character Issue)
I've got a program that uses stock tickers and, sometimes, CUSIPS as identifiers.
The Tickers work fine, but CUSIPS do not because, when fetching data from Bloomberg, EViews puts a "_" in front of the CUSIP.
The "_" at the start of the CUSIP causes the program to fail.
I'm trying to figure out how to have EViews put an alpha character (any character is fine) other than a "_" when creating a fetched series.
Any and all help would be greatly appreciated!
Kevin
My fetch command:
fetch bloom:: @BDH({%i} US EQUITY,DEBT_TO_MKT_CAP,,,PER=AQ)
The Tickers work fine, but CUSIPS do not because, when fetching data from Bloomberg, EViews puts a "_" in front of the CUSIP.
The "_" at the start of the CUSIP causes the program to fail.
I'm trying to figure out how to have EViews put an alpha character (any character is fine) other than a "_" when creating a fetched series.
Any and all help would be greatly appreciated!
Kevin
My fetch command:
fetch bloom:: @BDH({%i} US EQUITY,DEBT_TO_MKT_CAP,,,PER=AQ)
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13307
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Series Name Challenge ("_" Starting Character Issue)
Did you try the p= option on the fetch command?
Follow us on Twitter @IHSEViews
Re: Series Name Challenge ("_" Starting Character Issue)
That looks interesting...
How world I use that conditinally? For example, if the symbol/cusip starts with a number then add an “a” as the first character of the created series in n EViews. If the first character is already an “alpha” character then just create the fetched series without adding an “a” to the start of the name of the created series??
Many thanks!
KC
How world I use that conditinally? For example, if the symbol/cusip starts with a number then add an “a” as the first character of the created series in n EViews. If the first character is already an “alpha” character then just create the fetched series without adding an “a” to the start of the name of the created series??
Many thanks!
KC
Re: Series Name Challenge ("_" Starting Character Issue)
I tried putting p=bbrg but I get the following error:
My Code: fetch(p=bbrg_) bloom:: @BDH({%i} US EQUITY,DEBT_TO_MKT_CAP,,,PER=AQ)
Database Error: Bloomberg library error: 'Invalid Security BBRG_ ' in "FETCH(P=BBRG_) BLOOM:: @BDH(MSFT US EQUITY,DEBT_TO_MKT_CAP,,,PER=AQ)"
My Code: fetch(p=bbrg_) bloom:: @BDH({%i} US EQUITY,DEBT_TO_MKT_CAP,,,PER=AQ)
Database Error: Bloomberg library error: 'Invalid Security BBRG_ ' in "FETCH(P=BBRG_) BLOOM:: @BDH(MSFT US EQUITY,DEBT_TO_MKT_CAP,,,PER=AQ)"
Last edited by kcaron on Mon Mar 29, 2021 11:24 am, edited 1 time in total.
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13307
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Series Name Challenge ("_" Starting Character Issue)
If you don't like the "_" could you replace it after the fetch using @replace?
Follow us on Twitter @IHSEViews
Re: Series Name Challenge ("_" Starting Character Issue)
I tried that yesterday, but couldn't figure out how to write that code.
Any chance you might be able to help?
If it is a cusip (rather than a ticker), I would like to replace the first "_" with a letter value.
KC
Any chance you might be able to help?
If it is a cusip (rather than a ticker), I would like to replace the first "_" with a letter value.
KC
Re: Series Name Challenge ("_" Starting Character Issue)
Here is what I'm trying with Dell's cusip (1683997D)...
When I fetch, EViews creates this series: _1683997D_US_CUR_MKT_CAP
Then, I run this code @replace(_1683997d_us_cur_mkt_cap, "_", "a") to try to replace "_" with "a"... And I get this error:
Non numeric argument in "@REPLACE(_1683997D_US_CUR_MKT_CAP, "_", "A")"
And, what is really causing the issue in the first place is this message which occurs further on down in the code. This is the reason why I think I need to put a letter at the start of the cusips (because this only happens with cusips and not tickers). {%I} is a bunch of tickers and a few cusips that are fed into a loop.
Root Issue:
1683997D_MULT is an illegal or reserved name in "FRML {%I}_MULT = (1683997D_US_CUR_MKT_CAP + (1683997D_US_CUR_MKT_CAP * 1683997D_US_DEBT_TO_MKT_CAP) + 1683997D_US_PREFERRED_EQUITY___MINORITY_INT)/ 1683997D_US_TRAIL_12M_NET_SALES"
When I fetch, EViews creates this series: _1683997D_US_CUR_MKT_CAP
Then, I run this code @replace(_1683997d_us_cur_mkt_cap, "_", "a") to try to replace "_" with "a"... And I get this error:
Non numeric argument in "@REPLACE(_1683997D_US_CUR_MKT_CAP, "_", "A")"
And, what is really causing the issue in the first place is this message which occurs further on down in the code. This is the reason why I think I need to put a letter at the start of the cusips (because this only happens with cusips and not tickers). {%I} is a bunch of tickers and a few cusips that are fed into a loop.
Root Issue:
1683997D_MULT is an illegal or reserved name in "FRML {%I}_MULT = (1683997D_US_CUR_MKT_CAP + (1683997D_US_CUR_MKT_CAP * 1683997D_US_DEBT_TO_MKT_CAP) + 1683997D_US_PREFERRED_EQUITY___MINORITY_INT)/ 1683997D_US_TRAIL_12M_NET_SALES"
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13307
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Series Name Challenge ("_" Starting Character Issue)
In EViews, object names cannot start with a number, which is why EViews appends the _.
Once the renaming has occurred you cannot refer to the object by its original bbg name since that name doesn’t exist. You have to refer to it by its EViews name.
The first argument to the @replace function must be in quotes
Once the renaming has occurred you cannot refer to the object by its original bbg name since that name doesn’t exist. You have to refer to it by its EViews name.
The first argument to the @replace function must be in quotes
Follow us on Twitter @IHSEViews
Re: Series Name Challenge ("_" Starting Character Issue)
Thank you.
I tried putting the reference to the series in quotes, but nothing happens when I run the code.
Series Name: _1683997d_us_cur_mkt_cap
Code: @replace("_1683997d_us_cur_mkt_cap", "_", "a")
Attaching example workfile and program.
I'm thinking that if I can "trick" EViews to stop it from putting "_" in front of CUSIPS (numeric values) and put an alpha character instead, the issue would be solved. The code would need to look at each series fetched; determine if the EViews name begins with a "_"; if yes replace "_" with "a" (or something); otherwise do nothing.
Thanks for your help!
Kevin
I tried putting the reference to the series in quotes, but nothing happens when I run the code.
Series Name: _1683997d_us_cur_mkt_cap
Code: @replace("_1683997d_us_cur_mkt_cap", "_", "a")
Attaching example workfile and program.
I'm thinking that if I can "trick" EViews to stop it from putting "_" in front of CUSIPS (numeric values) and put an alpha character instead, the issue would be solved. The code would need to look at each series fetched; determine if the EViews name begins with a "_"; if yes replace "_" with "a" (or something); otherwise do nothing.
Thanks for your help!
Kevin
- Attachments
-
- example_workfile.wf1
- (11.87 KiB) Downloaded 135 times
-
- example_program.prg
- (48 Bytes) Downloaded 160 times
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13307
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Series Name Challenge ("_" Starting Character Issue)
Code: Select all
%listof_vars = @wlookup("_*", "series")
for %j {%listof_vars}
%name = "a" + @mid(%j,2)
rename {%j} {%name}
next
Follow us on Twitter @IHSEViews
Re: Series Name Challenge ("_" Starting Character Issue)
Gareth,
Thank you for the code.
Is there a function similar to ISNUMBER in excel? I need to look at the first character of each symbol/cusip and determine if I am dealing with a symbol (1st character is alpha) or cusip (1st character is number).
I could simply create a variable that is equal to “_” if first character is a number and add that variable throughout the program whenever I encounter a cusip.
But I need a function to test if the leftmost character in each symbol/cusip is a letter or number first.
K
Thank you for the code.
Is there a function similar to ISNUMBER in excel? I need to look at the first character of each symbol/cusip and determine if I am dealing with a symbol (1st character is alpha) or cusip (1st character is number).
I could simply create a variable that is equal to “_” if first character is a number and add that variable throughout the program whenever I encounter a cusip.
But I need a function to test if the leftmost character in each symbol/cusip is a letter or number first.
K
Re: Series Name Challenge ("_" Starting Character Issue)
Gareth,
Thank you for the code, but I think there is an even simpler way...
Is there a function similar to ISNUMBER in excel? I need to look at the first character of each symbol/cusip and determine if I am dealing with a symbol (1st character is alpha) or cusip (1st character is number).
I could simply create a variable that is equal to “_” if first character is a number and add that variable throughout the program whenever I encounter a cusip.
But I need a function to test if the leftmost character in each symbol/cusip is a letter or number first.
K
Thank you for the code, but I think there is an even simpler way...
Is there a function similar to ISNUMBER in excel? I need to look at the first character of each symbol/cusip and determine if I am dealing with a symbol (1st character is alpha) or cusip (1st character is number).
I could simply create a variable that is equal to “_” if first character is a number and add that variable throughout the program whenever I encounter a cusip.
But I need a function to test if the leftmost character in each symbol/cusip is a letter or number first.
K
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13307
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Series Name Challenge ("_" Starting Character Issue)
Code: Select all
if @val("_") <> NA
is functionally the same as isnumber
Follow us on Twitter @IHSEViews
Re: Series Name Challenge ("_" Starting Character Issue)
Ok... Thank you again... I've written this sample code, but get a "is not defined error."
Can you see what I'm doing wrong?
for %i MSFT GE CSCO 1683997D WMT INTC
%cusip = ""
If @val(@left({%i},1)) = 1 then
%cusip = "_"
Endif
next
Error Message: MSFT is not defined in "IF @VAL(@LEFT(MSFT,1)) = 1 THEN"
Can you see what I'm doing wrong?
for %i MSFT GE CSCO 1683997D WMT INTC
%cusip = ""
If @val(@left({%i},1)) = 1 then
%cusip = "_"
Endif
next
Error Message: MSFT is not defined in "IF @VAL(@LEFT(MSFT,1)) = 1 THEN"
Re: Series Name Challenge ("_" Starting Character Issue)
Wait! I figured it out!
I need to remove the {} from {%i}!
:-)
KC
I need to remove the {} from {%i}!
:-)
KC
Who is online
Users browsing this forum: No registered users and 27 guests