Command Reference : String and Date Function Reference
  
 
@val
Syntax: @val(str[, fmt])
Argument 1: string, str
Argument 2: numeric format string, fmt
Return: scalar
Returns the number that a string str represents. You may provide an optional numeric format string fmt.
In most cases, EViews will be able to convert your string into the corresponding numeric value without additional input. If EViews is unable to perform a conversion, it will return a missing (NA) value.
There are a few important conventions used in the conversion process:
A leading “$” in the string will be ignored.
Strings enclosed in “( )” or with a leading “–” will be treated as negative numbers. All other numeric strings, including those with a leading “+” will be treated as positive numbers. You may not have a leading “+” or “–” inside of the parentheses.
A trailing “%” sign instructs EViews to treat the input string as a percentage—the resulting value will be divided by 100.
There are some situations where you must provide a numeric format string so that EViews can properly interpret your input. The syntax for the format string depends on the type of number the string represents.
Real-Value Formats
EViews will properly interpret non-delimited decimal and scientific notation numeric input strings as numbers.
If your string uses “,” to separate thousands, you should specify the “t” format string to remove “,” delimiters prior to conversion. If the string uses “.” to separate thousands, you should use “t..” to instruct EViews to remove “.” delimiters.
If your input string represents a number with suppressed decimal format, you should include a format string beginning with the letter “s”:
 
s.precision
suppressed decimal point format (precision determines the number of digits to the right of the decimal)
EViews will divide the resulting number by 10 raised to the power of the specified precision. The “s” format specification may be followed by a “t.” or a “t..” specification if necessary.
Integer Formats
 
r
ratio (e.g., “30 1/5”).
i
integer
h
hexidecimal
o
octal
b
binary
You should use the “r”, “h”, “o”, or “b” formats to indicate that your input is in the specified format. The “i” format is generally not necessary unless you wish to produce a missing value for a non-integer input string.
Examples
scalar num = @val("$1.23")
assigns the scalar NUM the numeric value 1.23.
series ser1 = @val("-$123.88")
returns the value -123.88.
scalar sperct = @val("478%")
divides the value by 100, setting the scalar SPERCT to 4.78.
scalar sratio = @val("(321 1/5)", "r")
sets the scalar SRATIO equal to -321.2
scalar shexa = @val("f01a", "h")
treats the string “f01a” as a hexadecimal number, converts it into the decimal equivalent, 61466, and assigns it to the scalar object SHEXA.
scalar sbin = @val("11110101", "b")
interprets the string “11110101” as a binary number, converts it into the decimal equivalent, 245, and assigns it to the scalar SBIN.
To verify that a value is an integer, you may use the “i” option.
scalar sintna = @val("98.32", "i")
scalar sint = @val("96", "i")
SINTNA will contain a missing value NA since the input represents a non-integer value, while SINT is set to 96.
See also @str.