Command Reference : String and Date Function Reference : @str : Basic Formats
  
 
@sfill
Create a string vector.
Syntax: @sfill(str1[, str2, str3, ...])
str1: string
strs: string str2, str3, ...
Return: svector
Returns an svector containing strings specified in a comma separated list of strings.
Examples
If string list SS01 contains “A B C D E F”, then
svector s1 = @sfill("A", "B", "C", "D", "E", "F")
returns the 6 element svector S1, where row one of S1 contains “A”, row two contains “B”, etc.
svector s2 = @sfill("my apples", "your oranges", "our pears")
creates a 3 element svector S2, with the rows containing “my apples”, “your oranges”, and “our pears”.
Cross-references
See also @wsplit. See @wjoin for obtaining a string from an svector.
 
@str
 
String representation of number.
Syntax: @str(d[, fmt])
d: number
fmt: (optional) numeric format string
Return: string
Returns a string representing in d. You may provide an optional format string, fmt.
By default, EViews will format the number string using 10 significant digits, with no leading or trailing characters, no thousands separators, and an explicit decimal point.
(The default conversion is equivalent to using @str with the format “g.10” as described below.)
You may provide an explicit format string fmt to write your number in a specific fashion. A numeric format string has the format:
[type][t][+][(][$][#][<|=|>][0][width][[.|..]precision][%][)]
There are a large number of syntax elements in this format but we may simplify matters greatly by dividing them into four basic categories:
format: [type]
width: [<|=|>][width]
precision: [precision]
advanced modifiers: the remaining elements (leading and trailing characters, padding and truncation modifiers, separators, display of negative numbers)
The type, width, and precision components are the basic components of the format so we will focus on them first. We describe the advanced modifiers in “Modified Formats”.
Basic Formats
EViews offers formats designed for both real-valued and integer data.
Basic Real-Value Formats
The basic real-value format is:
[type][<|=|>][width][.][precision]
The type component is a single character indicating the basic type and the width and precision arguments are numbers indicating the number of output characters and the precision at which the numbers should be written. If specified, the precision should be separated from the type and width portion of the format by a “.” character (or “..” as we will see in “Modified Formats”).
If you specify a format with neither width nor precision, EViews will format the number at full precision with matching string width.
The following types are for use with real-valued data:
 
g
significant digits
z
significant digits with trailing zeros
c
fixed characters with single leading space for positive numbers
f
fixed decimal places
e
scientific/float
p
percentage (same as “f” but values are multiplied by 100)
s
suppressed decimal point format
r
ratio, e.g., “30 1/5”
The type character may be followed by a width specification, consisting of a width indicating the number of output characters, optionally preceded by a “>”, “=” or “<” modifier.
If no width is provided, the number will be rendered in a string of the exact length required to represent the value (e.g., the number 1.23450 will return “1.2345”, a string of length 6).
If an unmodified width or one with the “>” modifier is provided, the specified number places a lower-bound on the width of the string: the output will be left-padded to the specified width, if necessary, otherwise the string will be lengthened to accommodate the full output. By default, padding will use spaces, but you may elect to use 0’s by providing an advanced modifier ( “Modified Formats”).
If the“<” modifier is provided along with width, the width places an upper-bound on the width of the string: the output will not be padded to the specified width. If the number of output characters exceeds the width, EViews will return a width-length string filled with the “#” character.
If the“=” modifier is provided along with width, the width provides an exact-bound for the width of the string: the output will be padded to specified width, if necessary. If the number of characters exceeds the width, EViews will return a width-length string filled with the “#” character.
If you specify a precision, the interpretation of the value will vary depending on the format type. For example, precision represents the number of significant digits in the “g” and “z” formats, the number of characters in the “c” format, and the number of digits to the right of the decimal in the “f”, “e”, “p”, and “s” formats. For the “r” format, the precision determines maximum denominator for the fractional portion (as a power-of-10).
The following guidelines are used to determine the precision implied by a number format:
If you specify a format with only a precision specification, the precision will implicitly determine the width at which your numbers are written.
If you specify a format with only a width specification, the width will implicitly determine the precision at which your numbers are written. Bear in mind that only the modified width specifications “=width” and “<width” impose binding restrictions on the precision.
If you specify a format using both width and precision, the precision at which your numbers are written will be determined by whichever setting is most restrictive (i.e., “f=4.8” and “f=4.2” both imply a formatted number with two digits to the right of the decimal).)
Basic Integer Formats
The basic integer format is:
[type][<|=|>][width]
The type component is a single character indicating the basic type. The following types are for use with integer data:
 
i
integer
h
hexadecimal
o
octal
b
binary
If one of the integer formats is used with real-valued data, the non-integer portion of the number will be ignored. You may specify a width using the syntax and rules described in “Basic Real-Value Formats”.
Modified Formats
Recall that the syntax of a numeric format string is given by:
[type][t][+][(][$][#][<|=|>][0][width][[.|..]precision][%][)]
In addition to the basic type, width, and precision specifiers, the formats take a set of modifiers which provide you with additional control over the appearance of your output string:
You may combine any of the real-value format characters (“g”, “e”, “f”, etc.) with the letter “t” (“gt”, “et”, “ft”, etc.) to display a thousands separator (“1,234.56”). By default, the separator will be a comma “,”, but the character may be changed to a “.” using the “..” format as described below.
You may add a “+” symbol after the format character (“g+”, “et+”, “i+”) to display positive numbers with a leading “+”.
To display negative numbers within parentheses, you should enclose the remaining portion of the format in parentheses “ft+($8.2)”.
Add “$” to the format to display a leading “$” currency character.
You should include a “#” to display a trailing point in scientific notation (e.g., “3.e+34”).
The width argument should include a leading zero (“0”) if you wish padded numbers to display leading zeros instead of spaces (“g08.2”, “i05”).
If you added a “t” character to your real-value format type, you may replace the usual “.” width-precision separator with “..” (“ft<08..2”, “e=7..”, “g..9”, etc.) to reverse the thousands and decimal separators so that thousands will be separated by a “.” and decimal portion by a “,” (“1.234,56”).
Adding a “%” character to the end of the format adds the “%” character to the end of the resulting string.
Examples
string num = @str(1.23)
assigns to the string NUM the text “1.23”.
alpha alpha1 = @str(-123.88)
assigns the string “-123.88” to the alpha series ALPHA1.
string num = @str(123456,"z.9")
returns a string formatted to 9 significant digits with trailing zeros: “123456.000”.
string num = @str(123456,"z.4")
returns a string formatted to 4 significant digits with trailing zeros: “1.235e+05”. Note that since the input number has more than 4 significant digits, no trailing zeros are added and the resulting string is identical to one that would have been produced with a “g.4” format.
string num = @str(126.543,"c.7%")
returns a string with exactly 7 characters, including a leading space, and a trailing percent sign: “ 126.5%”.
string num = @str(126.543,"p.7")
converts the number 126.543 into a percentage with 7 decimal places and returns “12654.3000000”. Note no percent sign is included in the string.
string num = @str(1.83542,"f$5.4")
returns “$1.8354”. The width selection of “5” with an implicit “>” modifier is irrelevant, since the precision setting of “4”, coupled with the insertion of the “$” symbol yields a string with more characters than “5”.
string num = @str(1.83542,"f$8.4")
returns “ $1.8354”. Here the width selection is binding, and a leading space has been added to the string.
string num = @str(1.83542,"f$=5.4")
returns “ $1.84”. The explicit “=” width modifier causes the width setting of “5” to be binding.
string num = @str(524.784,"r")
converts the number 524.784 into a ratio representation: “524 98/125”.
string num = @str(1784.321,"r=3")
will return “###”, since there is no way to represent 1784.321 as a string with only 3 characters.
string num = @str(543,"b")
converts the number 543 into a binary representation: “1000011111”.
The matrix command
svector svec1 = @str(v1)
converts the numeric values of vector V1 to strings and puts the results in the svector SVEC1. If the svector SVEC1 exists it will be sized to match the rows of V1 and missing values will be converted to empty strings.
The series command
alpha a1 = @val(gdp)
creates the alpha series A1 and converts the numeric values of series GDP to string. NA values will be become empty strings.
Format strings may be used to govern the conversion,
svector svbin = @str(vec1, "e")
converts the numeric values in the vector VEC1 into their strings representation in scientific notation and assigns them to the svector SVBIN.
Cross-references
See @val to interpret strings as numbers.
 
@strdate
 
String representation of the dates of the observation.
Syntax: @strdate(fmt)
fmt: date format string
Return: alpha
Fill an alpha series with workfile dates as strings, using the date format string fmt, for each observation in the workfile sample. Only observations in the workfile sample will be filled.
Date format syntax is outlined in “Date Formats”.
@strdate is a specialized form of a call to the @datestr function, applied to all of the observations in the workfile.
Examples
The commands
alpha wfdates1 = @strdate("yyyy/mm/dd")
alpha wfdates2 = @datestr(@date, "yyyy/mm/dd")
fill the alpha series WFDATES1 and WFDATES2 with the corresponding workfile dates in “yyyy/mm/dd” format.
alpha hmsdates = @strdate("yyyy-MM-DD HH:mi:ss")
fills the alpha series HMSDATES with the workfile dates in "yyyy-MM-DD HH:mi:ss" format.
Cross-references
See @datestr and @strnow for other functions to obtain date strings.
See @dateval for converting date strings to date numbers.