Function Reference: W
@wcount Number of words in the string list.
@wcross String with words in first list crossed with second.
@wdelim Replace delimiters in string.
@wdir List of all files in a directory.
@wdrop Drop words from string list.
@weekday Day of the week of the observation.
@wexpand String representation of automatic dummy variables.
@wfattrnames String containing a list of attribute names in the workfile.
@wfattrvals String containing a list of attribute values in the workfile.
@wfind Find location of word (case-sensitive) in string list.
@wfname String containing name of current workfile.
@wfindnc Find location of word (not case-sensitive) in string list.
@wfpath String containing path of current workfile.
@winsert Insert string into string after word.
@wjoin Extract elements of an Svector to a string.
@wkeep Keep subset of words in string list.
@wleft Left-most words of string list.
@wlookup String list formed from objects in a workfile or database matching a pattern.
@wmid Middle or middle to end words of a string list.
@wnotin Words not in a string list.
@word Single word from a string list.
@wordq Single word from a string list, preserving quotes.
@wquery String containing list of object attributes for objects matching a database query.
@wread Read contents of text file into a string.
@wreplace Replace characters in each word in a string list.
@wrfind Find location of a word (case-sensitive) in a string list searching from end.
@wrfindnc Find location of a word (not case-sensitive) in a string list searching from end.
@wright Right-most words of a string list.
@wsort Sorted list of words in a string list.
@wsplit Create string vector from words in a string list.
@wunion Union of words in two string lists.
@wunique Remove duplicate words in string list.
Number of words in the string.
Syntax: @wcount(str_list)
str_list: string
Return: integer
Example
The commands
string s1 = "I did not do it"
@wcount("I did not do it")
@wcount(s1)
return the number 5.
If ALPHA1 is an alpha series,
scalar alphalwr = @wcount(alpha1)
returns the number of words in the strings in ALPHA1 for each observation in the workfile sample.
If SVEC1 is an string vector,
vector sveclen = @wcount(svec1)
returns a the number of elements in each of the strings in SVEC1.
Cross-references
See also
@len for the length of the strings.
String with words in first list crossed with second.
Syntax: @wcross(str_list1, str_list2[, pattern])
str_list1: string
str_list2: string
pattern: string
Return: string list
Returns str_list1 crossed with str_list2, using the string pattern. The default pattern is “??”, which indicates that each element of str_list1 should be crossed individually with each element of str_list2.
Examples
@wcross("A B C", "1 2 3 4")
returns every combination of the elements “A B C” and “1 2 3 4”, using the default pattern “??”. This produces the string list: “A1 A2 A3 A4 B1 B2 B3 B4 C1 C2 C3 C4”.
@wcross("ABC DEF", "1 2 3", "?-?")
returns the string list “ABC-1 ABC-2 ABC-3 DEF-1 DEF-2 DEF-3”, inserting a dash (“-”) between each crossed element as the “?-?” pattern indicates.
If ALPHA1 is an alpha series,
alpha alphacx = @wcross(alpha1, "1 2 3 4")
crosses the string lists in ALPHA1 with “1 2 3 4” for each observation in the workfile sample.
If SVEC1 and SVEC2 are string vectors,
svector sveccx = @wcross(svec1, svec2)
crosses the string list in SVEC1 with the corresponding string list in SVEC2 for each element of the two svectors.
Cross-references
Replace delimiters in string.
Syntax: @wdelim(str_list, src_delim, dest_delim)
str_list: string
src_delim string delimiter
dest_delim string delimiter
Return: string
Returns a string list, replacing every appearance of the src_delim delimiter in str_list with a dest_delim delimiter. Delimiters must be single characters.
Note that most other string list functions (those beginning with “@w”) require that the delimiter be a space (“ ”). Use this function to convert strings with other delimiters into those which can be used with the string list functions.
Examples
@wdelim("Arizona, California, Washington", ",", "-")
identifies the comma as the source delimiter and replaces each comma with a dash, returning the string “Arizona-California-Washington”.
If ALPHA1 is an alpha series,
alpha alphad = @wdelim(alpha1, ",", ":")
replaces each “,” with “:” in the string lists in ALPHA1, for each observation in the workfile sample.
If SVEC1 is a vector,
svector svecd = @wdelim(svec1, ",", ";")
replaces each delimiter “,” with “;” in the string lists in SVEC1 for each element.
Cross-references
Syntax: @wdir(d, t)
d: string
t: (optional) string
Return: string
The return_type may be one of the following:
“f” (default=”f”) | Return the list of files in the directory_str directory. |
“d” | Return the list of directories in the directory_str directory. |
“fd” | Return the list of files and directories in the directory_str directory. Note: directories will be denoted with a trailing \. |
Returns a string list of all files/directories in the directory directory_str.
Examples
@wdir("C:\Documents and Settings")
returns a string list containing the names of all files in the “C:\Documents and Settings” directory.
@wdir("C:\Documents and Settings", "fd")
returns a string list containing the names of all files and directories in the “C:\Documents and Settings” directory.
Cross-references
Drop words from string list.
Syntax: (str_list, pat_list)
str_list: string
pat_list: string
Return: string
Returns a string list, dropping elements in str_list that match the string pattern pat_list. The pat_list is space delimited and may be made up of any number of “?” (indicates any single character) or “*” (indicates any number of characters).
The pattern is case-sensitive and must exactly match the str_list characters to be dropped.
Examples
@wdrop("D D A B C", "B D C")
removes each instant of the elements “B”, “D”, and “C”, returning the string “A”.
@wdrop("ABC DEF GHI JKL", "?B? D?? *I")
drops the first three elements of the string list, returning the string “JKL”. The string pattern “?B?” drops “ABC”, the pattern “D??” drops “DEF”, and the pattern “*I” drops “GHI”.
If ALPHA1 is an alpha series,
alpha strdrop = @wdrop(alpha1, "B D C")
returns the string values of ALPHA1 after dropping “B D C” for each observation in the workfile sample.
If SVEC1 is an string vector,
svector strdrop = @wdrop(svec1, "*I")
returns an svector after dropping all elements that end in “I” from each element of SVEC1.
Cross-references
Day of the week of the observation.
Syntax: @weekday
Return: series
Returns the day of the week (1–7) associated with each observation in the workfile (Monday–Sunday).
• If the workfile is of lower than daily frequency, the day of the week will be first day of the period.
• If the workfile is undated, observations will be set to -1.
Examples
series dt = @weekday
saves the day of the week into the series DT.
The command
workfile d7 2020 2022
smpl if @weekday < 7
creates a seven day workfile and sets the sample to exclude Sundays.
Cross-references
@wexpand | Special Expression |
String representation of automatic dummy variables.
Return the string list associated with automatically created dummy variables from numeric or alpha series.
Syntax: @wexpand(ser1[, ser2, ser3, ...][, s]))
ser1: series, alpha
ser2...: series, alpha
s: (optional) sample string or object
Return: string
returns the string corresponding to the set of dummy variables that span the unique values of the input series ser1, ser2, etc. These may be numerical series with integer only values, alpha series or links.
By default, the definition of the categories will use the current workfile sample, but you may specify an explicit sample s.
Example
For example, consider the following two variables:
• SEX is a numeric series which takes the values 1 and 0.
• REGION is an alpha series which takes the values “North”, “South”, “East”, and “West”.
The command:
%str = @wexpand(sex)
yields the string SEXLIST containing “SEX=0 SEX=1”.
The @wexpand statement in,
%str = @wexpand(sex, region)
yields a space delimited string list SREGION with elements:
“SEX=0 AND REGION=""North""”
“SEX=0 AND REGION=""South""”
“SEX=0 AND REGION=""East""”
“SEX=0 AND REGION=""West""”
“SEX=1 AND REGION=""North""”
“SEX=1 AND REGION=""South""”
“SEX=1 AND REGION=""East""”
“SEX=1 AND REGION=""West""”
Cross-references
Syntax: @wfattrnames(attr[, obj, page, opt])
attr: string
obj: (optional) string
page: (optional) string
opt: (optional) integer
Return: string
Returns a string list of all attribute names that match the attr pattern in the specified page list or active page and, optionally, whose object names also match the obj name pattern.
• The attr is a space delimited list of attribute name patterns. The list may be made up of any number of names, or “?” (indicates any single character) or “*” (indicates any number of characters) patterns.
• The obj list may be made up of any number of names, or “?” (indicates any single character) or “*” (indicates any number of characters) patterns separated by spaces.
• The page list may be made up of any number of workfile page names, or “?” (indicates any single character) or “*” (indicates any number of characters) patterns separated by spaces. If a page list is not specified, only the active workfile page will be used.
• The opt is an integer value indicating how a “*” or “?” in the attr should be treated when matching. Use “0” to treat the characters as wildcards, and “1” to treat the characters as literals.
Matches are not case-sensitive.
Examples
If a workfile contains three pages named “PAGE1”, “PAGE2”, and “PAGE3”,
@wfattrnames("M*")
returns the list of attributes for the objects in the active page that begin with “M”. Alternatively,
@wfattrnames("M* S*", "*", "page1 page2")
returns the list of attributes for all the objects on PAGE1 and PAGE2 that begin with “M” and “S”.
If an object on PAGE1 had an attribute named “*Note” and another object on the same page had an attribute named “footnote” the command
@wfattrnames("*NOTE", "*", "page1")
will return “*Note footnote” since the “*” in “*Note” is treated as a wildcard. However, the command
@wfattrnames("*NOTE", "*", "page1", 1)
will return “*Note”, since the “*” in “*Note” is treated as a literal.
Cross-references
Syntax: @wfattrvals(attr[, obj, page, opt])
attr: string
obj: (optional) string
page: (optional) string
opt: (optional) integer
Return: string
Returns a string list of all attribute values that match the attr pattern in the specified page list or active page and, optionally, whose object names also match the obj name pattern.
• The attr is a space delimited list of attribute value patterns. The list may be made up of any number of names, or “?” (indicates any single character) or “*” (indicates any number of characters) patterns.
• The obj list may be made up of any number of names, or “?” (indicates any single character) or “*” (indicates any number of characters) patterns separated by spaces.
• The page list may be made up of any number of workfile page names, or “?” (indicates any single character) or “*” (indicates any number of characters) patterns separated by spaces. If a page list is not specified, only the active workfile page will be used.
• The opt is an integer value indicating how a “*” or “?” in the attr should be treated when matching. Use “0” to treat the characters as wildcards, and “1” to treat the characters as literals.
Matches are not case-sensitive.
Examples
If a workfile contains three pages named “PAGE1”, “PAGE2”, and “PAGE3”, then
@wfattrvals("M*", "*", "PAGE1")
return the string list of all attribute values that begin with “M” on PAGE1. Alternatively,
@wfattrvals("M* D*", "GDP", "PAGE1 PAGE2")
returns the list of attribute values for the objects PAGE1/GDP and PAGE2/GDP that begin with “M” and “D”.
If on PAGE1 there was an object that had one attribute value of “*Mar” and second attribute value of “Mar”, the command
@wfattrvals("*mar", "*", "PAGE1")
will return “*mar mar” since the “*” in “*mar” is treated as a wildcard and the values “Mar” and “*Mar” both match the attribute list. However, the command
@wfattrvals("*mar", "*", "PAGE1", 1)
will only return “*mar”, since the “*” in “*Mar” is treated as a literal and only “*Mar” matches the list.
Cross-references
Find location of word (case-sensitive) in string list.
Syntax: @wfind(str_list, str_cmp)
str_list: string
str_cmp: string
Return: integer
Looks for the string str_cmp in the string list str_list, and returns the position in the list or 0 if the string is not in the list.
• This function is case-sensitive; use the
@wfindnc function to ignore case.
• Note that this function works only on single words; for multiple or parts of words, use
@instr.
Examples
@wfind("I did it", "did")
returns the number 2, indicating the string “did” is second in the list.
@wfind("I did not do it", "i")
This function is case-sensitive and searches for the full string, so “i” will not be found and the function will return the number 0.
If ALPHA1 is an alpha series,
series stfind = @wfind(alpha1, "did")
returns the position of the string word “did” in the string list values of ALPHA1 for each observation in the workfile sample.
If SVEC1 is an string vector,
vector stfind = @wfind(svec1, "I")
returns the position of the string word “I” in the string lists in each element of SVEC1.
Cross-references
Find location of word (not case-insensitive) in string list.
Syntax: @wfindnc(str_list, str_cmp)
str_list: string
str_cmp: string
Return: integer
Looks for the string str_cmp in the string list str_list, and returns the position in the list or 0 if the string is not in the list.
• This function is similar to the
@wfind function, but is not case-sensitive
• Note that this function works only on single words; for multiple or parts of words, use
@instr.
Examples
@wfindnc("I did it", "DID")
returns the number 2, indicating the caseless string “did” is second in the list.
@wfindnc("I did not do it", "i")
returns the number 1, since the first “i” or “I” encountered was in the first position.
If ALPHA1 is an alpha series,
series stfind = @wfindnc(alpha1, "did")
returns the position of the string word “did” caselessly matching the string list values of ALPHA1 for each observation in the workfile sample.
If SVEC1 is an string vector,
vector stfind = @wfindnc(svec1, "I")
returns the position of the string word “I” caselessly matching words in the string lists in each element of SVEC1.
Cross-references
Name of current default workfile.
Syntax: @wfname
Return: string
Returns a string containing the name of the current default workfile.
Examples
The command
string temp = @wfname
saves the current workfile name in the string variable TEMP, while
%tmp = @wfname + "bak"
wfsave %tmp
extracts the current workfile name, adds the text “bak” and then saves the current workfile using the new name.
Cross-references
Path of current default workfile.
Syntax: @wfpath
Return: string
Returns a string containing the path (location) of the current default workfile.
Examples
The command
string temp = @wfpath
saves the current workfile path in the string variable TEMP, while
%tmp = @wfpath + @wfname + "bak"
wfsave %tmp
extracts the current workfile path and name, adds the text “bak” and then saves the current workfile using to the original path using the new name.
Cross-references
Insert string into a string.
Syntax: @winsert(str1, str2, n)
str1: string
str2: string
n: integer
Return: string
Inserts the string str2 into the string str1 after the word position given by the integer n.
Examples
string sval1 = "I believe it can be done"
string sval2 = "not"
= @winsert("I believe it can be done", "not", 4)
= @insert(sval1, sval2, 4)
= @insert(sval1, "not”, 4)
all return the string “I believe it can not be done”.
If ALPHA1 is an alpha series,
alpha a1 = @winsert(sval2, "not", 4)
creates an alpha series with the contents of ALPHA1 with the string “not ” after word45, for each observation in the workfile sample.
alpha a2 = @winsert(sval1, a1, ser1)
inserts SVAL1 into A1 after the integer word positions given in the series SER1.
If SVEC1 is an svector,
svector s1 = @winsert("(pretty please) ", svec1, 5)
inserts “(pretty please) ” into SVEC at after word 4.
Cross-references
Interleave words of two string lists.
Syntax: @winterleave(str_list1, str_list2[, n1, n2])
str_list1: string
str_list2: string
n1: (optional) integer
n2: (optional) integer
Return: string
Interleaves str_list1 with str_list2, according to the pattern specified by n1 and n2. The default uses counts of one.
Examples
@winterleave("A B C", "1 2 3")
interleaves “A B C” with “1 2 3” to produce the string list “A 1 B 2 C 3”.
@winterleave("A B C", "1 2 3 4 5 6")
interleaves “A B C” with “1 2 3 4 5 6”, returning the string list “A 1 B 2 C 3 “” 4”. Since there are more elements in the second string, empty strings (“”) are inserted when the elements of the first string run out.
Alternately, you may specify a count pattern to control the spacing of elements:
@winterleave("A B C", "1 2 3 4 5 6", 1, 2)
This command combines one element of the first string for every two elements of the second string, returning “A 1 2 B 3 4 C 5 6”.
If ALPHA1 is an alpha series,
alpha alphacx = @winterleave(alpha1, "1 2 3 4")
interleaves the string lists in ALPHA1 with “1 2 3 4” for each observation in the workfile sample.
If SVEC1 and SVEC2 are string vectors,
svector sveclen = @winterleave(svec1, svec2, 1, 2)
interleaves the string list in SVEC1 with the corresponding string list in SVEC2 for each element of the two svectors, using one element of the SVEC2 strings for every two elements of the SVEC2 strings.
Cross-references
Intersection of words in two string lists.
Syntax: @wintersect(str_list1, str_list2)
str_list1: string
str_list:2 string
Return: string
Returns the elements that are in both str_list1 and str_list2. This function is case-sensitive.
Examples
@wintersect("John and Greg won", "Greg won with Mark's help")
returns the string “Greg won”.
Since this function is case-sensitive,
@wintersect("John and Greg won", "greg won with Mark's help")
just returns the string “won”.
If ALPHA1 and ALPHA2 are alpha series,
alpha stinter = @wintersect(alpha1, alpha2)
returns the intersection of values for elements of ALPHA1 and ALPHA2 for each observation in the workfile sample.
If SVEC1 and SVEC2 are string vectors,
svector stinter = @wintersect(svec1, svec2)
returns an svector containing the intersection of the elements in SVEC1 and SVEC2 for each element of the svectors.
Cross-Reference
Extract elements of an Svector to a string.
Syntax: @wjoin(svec)
svec: svector
Return: string
Returns a space delimited list containing the elements of svec.
Examples
If svector SVEC has 7 rows with each row being the corresponding letter of the alphabet (row 1 has “A”, row 2 has “B” and so on), then
@wjoin(svec)
returns a “A B C D E F G”.
Cross-Reference
See also
@wsplit for creating an svector from a string.
Keep subset of words in string list.
Syntax: (str_list, pat_list)
str_list: string
pat_list: string
Return: string
Returns the list of elements in str_list that match the string pattern pat_list. The pat_list is space delimited and may be made up of any number of “?” (indicates any single character) or “*” (indicates any number of characters).
The pattern is case-sensitive and must exactly match the str_list characters to be kept.
Examples
@wkeep("D D A B C", "B D C")
returns all matching elements in pattern_list that are found in str_list: “D D B C”.
@wkeep("ABC DEF GHI JKL", "?B? D?? *I")
keeps the first three elements of the string list, returning the string “ABC DEF GHI”. The string pattern “?B?” keeps “ABC”, the pattern “D??” keeps “DEF”, and the pattern “*I” keeps “GHI”.
If ALPHA1 is an alpha series,
alpha strkeep = @wkeep(alpha1, "B* D* C*")
returns the string values of ALPHA1 keeping only word elements that begin with “B”, “D”, or “C”, for each observation in the workfile sample.
If SVEC1 is an string vector,
svector strkeep = @wkeep(svec1, "*I")
returns an svector after keeping all elements that end in “I” from each element of SVEC1
Cross-references
Left-most words of string list.
Syntax: @wleft(str_list, n)
str_list: string
n: integer
Return: string
Returns a string list containing the left n word elements of string list str_list. If the string list str_list is shorter than n elements, this function returns all of the elements in the source string.
Examples
The commands
string orig = "I did not do it"
string sc1 = @wleft("I did not do it", 2)
string sc2 = @left(orig, 2)
return the string objects SC1 and SC2 containing the string “I did”.
If ALPHA1 is an alpha series,
alpha strleft = @left(alpha1, 3)
returns the left-most 3 words from the string values of ALPHA1 for each observation in the workfile sample.
If SVEC1 is an string vector,
svector strleft = @left(svec1, 2)
returns an svector containing 2 words from the left end of each element of SVEC1.
Cross-references
See also
@left,
@wright and
@wmid.
Lookup objects in workfile or database.
Syntax: @wlookup(obj[, type, [attr, [opt]]])
obj: string
type: (optional) string
attr: (optional) string
opt: (optional) integer
Return: string
Returns a string list of all objects in the workfile or database that match the name pattern list and, optionally, the type object type list and the attr attribute pattern using the opt search option.
• The obj list may be made up of any number of names, or “?” (indicates any single character) or “*” (indicates any number of characters) patterns separated by spaces. The pattern must exactly match the object name in the workfile or database.
• The type is a space delimited list containing one or more object types. The default is “*”. Object types are "*", "sample", "svector", "equation", "graph", "table", "text", "program", "model", "system", "var", "string", "pool", "sspace", "logl", "alpha", "valmap", "factor", "spool", "graph", "userobj", "group+data", "group", "scalar", "mat/vec/sym", "coeflist","group", "matveclist", "sym", "matrix", "vector", "coef", "series", "link", "digraph", "geomap", "string", "formula", "database", and "workfile".
• The attr is a space delimited list of attribute value patterns made up of any number of names, or “?” (indicates any single character) or “*” (indicates any number of characters) patterns separated by spaces. The default is “”.
• The obj is an integer value indicating how a “*” in the attr should be treated when matching. Use “0” to treat “*” as a wildcard and “1” to treat “*” as a literal. The default is “0”.
Examples
If a workfile contains three graph objects named “GRA1”, “GRA2”, and “GRA01”, one group object named “GRO1”, and two series objects named “SR1” and “SER2”, then
@wlookup("GR*")
returns the string list “GRA01 GRA1 GRA2 GRO1”. All objects beginning with “GR” and followed by any number of characters are included. Alternatively,
@wlookup("?R*")
returns the string list “GRA1 GRA2 GRA01 GRO1 SR1”. SER2 is not included because “?” specifies a single character preceding an “R”.
@wlookup("?R?","series")
returns the string “SR1”. The object type “series” drops all graph objects from the list, and “?R?” filters out SER2 because “?” specifies a single character.
Now let us assume for the same workfile:
• GRA1 had the attributes “Month” and “Author” with values equal to “September” and “Sam”.
• GRA2 had the attribute “Author” with value equal to “Sam”.
• GRA01 had the attributes “Month” and “Author” with values equal to “January” and “Mary”.
• GRO1 had the attribute “Month” with value equal to “September”.
• SRO1 had the attribute “Mon” with value equal to “January”.
• SER2 had the attributes “Month” and “Author” with values equal to “June” and “Sam”.
We limit the results by adding attribute filters
@wlookup("GR*", "*”, "Month=J*")
returns the string list “GRA01”. “GRA01” was the only object that had the “Month” attribute value beginning with “J”.
@wlookup("*", "*", "Month=September Month=J*")
returns the string “GRA01 GRA1 GRO1 SER2”. All objects either had a “Month” equal to “September” or “Month” beginning with “J”.
@wlookup("*", "GRAPH", "Month=September Month=J*")
returns the string “GRA01 GRA1”. Only graph objects which either had a “Month” equal to “September” or “Month” beginning with “J” are included.
@wlookup("*", "*", "Month=*")
returns the string “GRA01 GRA1 GRO1 SER2”. All objects have a “Month” attribute whereby the value is ignored.
@wlookup("*", "SERIES", "Month=*")
returns the string “SER2”. Only the series objects which have a “Month” attribute are included.
@wlookup("*", "*", "M*th=September")
returns the objects which have attributes beginning with “M” and ending with “th”. This returns the string “GRA1 GRO1”.
Cross-references
Middle or middle to end words of a string list.
Syntax: @wmin(str_list, n1[, n2])
str_list: string
n1: integer
n2: (optional) integer
Return: string
Returns n2 elements from str_list, starting at element n1 and continuing to the right for n2 elements. If you omit n2, the function will return all of the remaining elements in the string.
Examples
The command
string s1 = @wmid("I really don’t doubt it", 4)
assigns “doubt it” to the string object S1, while
string s2 = @wmid("I really doubt it", 2, 2)
assigns “really doubt” to S2.
If ALPHA1 is an alpha series,
alpha strleft = @wmid(alpha1, 3)
returns the remaining words beginning with the 3rd from the string values of ALPHA1, for each observation in the workfile sample.
If SVEC1 is an string vector,
svector strleft = @mid(svec1, 4, 2)
returns an svector beginning at the 5th for 2 words for each element of SVEC1.
Cross-references
See also
@mid,
@wleft and
@wright.
Words not in a string list.
Syntax: (str_list1, str_list2)
str_list1: string
str_list2: string
Return: string
Returns elements of str_list1 that are not in str_list2. This function is case-sensitive.
Examples
string employee1 = @wnotin("Full Name: John Smith", "Full Name:")
string employee2 = @wnotin("Full Name: Mary Jones", "Full Name:")
assigns the string “John Smith” to the string object EMPLOYEE1, and the string “Mary Jones” to the string object EMPLOYEE2.
@wnotin("John and Greg won", "and Greg")
returns the string “John won”.
If ALPHA1 is an alpha series,
alpha strnot = @wnotin(alpha1, "and or not")
returns the strings in ALPHA1 with the words “and”, “or”, and “not” removed, for each observation in the workfile sample.
If SVEC1 is an string vector,
svector strnot = @wnotin(svec1, "and or not")
returns an svector with each string element of SVEC1 after removing “and”, “or”, and “not”.
Cross-references
Single word from a string list.
Syntax: (str_list, n)
str_list: string
n: integer
Return: string
Returns the
n-th element from the string list
str_list, not including surrounding double-quotes. This function is the same as the
@wordq function, but removes quotes.
Examples
@word("I don’t think so", 2)
returns the second element, “don’t”.
@wordq("""Chicken Marsala"" ""Beef Stew""", 2)
returns the second element, “Beef Stew”, without the surrounding double-quotes.
If ALPHA1 is an alpha series,
alpha str1 = @word(alpha1, 3)
returns the third word of the string lists in ALPHA1, while
alpha str2 = @word(alpha1, ser1)
returns the word in the string lists in ALPHA1 given by the integers in the series SER, for each observation in the workfile sample.
If SVEC1 is an string vector,
svector str3 = @word(svec1, 5)
returns an svector with the fifth word in each element of SVEC1”.
Cross-references
Single word from a string list, preserving quotes.
Syntax: (str_list, n)
str_list: string
n: integer
Return: string
Returns the
n-th element from the string list
str_list, retaining surrounding double-quotes. This function is the same as the
@word function, but preserving quotes.
Examples
@wordq("""Chicken Marsala"" ""Beef Stew""", 2)
returns the second element, ‘“Beef Stew”’ including the surrounding double-quotes.
If ALPHA1 is an alpha series,
alpha str1 = @wordq(alpha1, 3)
returns the potentially quoted third word of the string lists in ALPHA1, while
alpha str2 = @wordq(alpha1, ser1)
returns the potentially quoted word in the string lists in ALPHA1 given by the integers in the series SER, for each observation in the workfile sample.
If SVEC1 is an string vector,
svector str3 = @wordq(svec1, 5)
returns an svector with the potentially quoted fifth word in each element of SVEC1”.
Cross-references
Object attributes from database query.
Syntax: @wquery(db[, str, attr])
db: string
str: (optional) string
attr: (optional) string
Return: string
Returns a string list of object attributes for all objects in the database named db that satisfy the query specified by str. The search expression str should be a standard database query.
By default @wquery will return the name of the objects in the database that match the search criteria. However you may specify other object attributes to be returned, by listing them (comma delimited) in attr.
Examples
If a database, MYDB, contains a series object named “GDP_1” and a series called “GDP_2”, with the first being annual frequency and the second being quarterly frequency, then
@wquery("mydb", "name matches GDP* and freq=Q", "name")
returns the string “GDP_2”. Alternately,
@wquery("mydb", "name matches GDP* and freq=A", "name, freq")
returns the string list “GDP_1 A”.
@wquery("basics.edb", "freq = q and start>1970 and not scale=millions")
returns a string list of the names of all objects in the database BASICS.EDB with quarterly frequency and a start date after 1970 which do not have the custom attribute ‘scale’ set to ‘millions’.
@wunique(@wquery("mydb", "start>2000", "freq"))
returns a string list of all the frequencies of objects in the database whose start date is post 2000. Note that we use the @wunique function to remove duplicate frequencies from the list.
Cross-references
Read contents of text file into a string.
Syntax: @wread(filespec[, mode])
filespec: file name of a text file on disk.
mode: string
Return: string
Returns a (potentially preprocessed) string containing the contents of the specified text file on disk.
The mode parameter specifies how the contents are parsed into individual fields and processed before being concatenated and returned by the function. The mode parameter may be used to specify a delimiter, or to instruct EViews to bypass preprocessing.
The following mode options specify the delimiter used to separate the input text into fields prior to concatenation:
• “t” or “tabs” (tabs)
• “,” or “c”, or “comma” (commas)
• “cr” or “nl” (line breaks)
If no mode is specified, EViews will attempt to auto-detect the delimiter. If an individual field contains double quotation marks, those marks will be escaped (replaced by "") and the entire field will be surrounded by double quotation marks. Delimiters are removed from the returned string, and all non-printing characters are replaced with spaces.
The following option for mode instructs EViews to return the contents of the file unmodified with no field preprocessing:
• “raw”
Example
string s1 = @wread("c:\temp\myfile.txt")
returns a string containing the contents of “c:\temp\myfile.txt”. The contents of the file are split into fields using autodetected delimiters, the delimiters are removed, and the fields are concatenated using space delimiters with non-printing characters replaced with spaces.
string s2 = @wread("c:\temp\myfile.txt", "raw")
returns a string containing the raw contents of “c:\temp\myfile.txt”.
Replace characters in each word in a string list.
Syntax: @wreplace(str1, src_pat, rep_pat[, "all"])
str_list: string
src_pat: string
rep_pat: string
"all": (optional) string literal
Return: string
Replaces instances of str_list in str_list with rep_pat. The patterns may be made up of any number of “?” (indicates any single character) or “*” (indicates any number of characters).
The pattern is case-sensitive and must exactly match the src_pat characters to be replaced.
Only the first instance of src_pat within each word of str_list is replaced unless the optional flag “all” is specified (enclosed in quotes), in which case all instances within each word are replaced.
Examples
@wreplace("ABBC AB", "*B*", "*X*")
replaces the first instance of “B” with “X”, returning the string “AXBC AX”.
@wreplace("ABBC AB", "*B*", "*X*", "all")
replaces all instances of “B” with “X”, returning the string “AXXC AX”.
@wreplace("ABC DDBC", "??B?", "??X?")
replaces all instances of “B” which have two leading characters and one following character, returning the string “ABC DDXC”.
If ALPHA1 is an alpha series,
alpha alphaltrim = @wreplace(alpha1, "*ABC*", "*X*", "all")
replaces all instances of “ABC” with “X” in each word of the entries of ALPHA1 for each observation in the workfile sample.
If SVEC1 is an string vector,
svector sveclen = @wreplace(svec1, "In*", "")
returns a string vector containing elements of SVEC1 with the leading “In” in each word removed.
Cross-references
Find location of a word (case-sensitive) in a string list searching from end.
Syntax: @wrfind(str_list, str_cmp)
str_list: string
str_cmp: string
Return: integer
Looks for the last occurrence of string str_cmp in the string list str_list, and returns the position in the list or 0 if the string is not in the list.
• This function is case-sensitive; use the
@wfindnc function to ignore case.
• Note that this function works only on single words; for multiple or partial words, use
@instr.
Examples
= @wrfind("I did it. Did you?", "Did")
returns the number 4, indicating the string “Did” is 4th in the list.
= @wrfind("I did not do it", "i")
This function is case-sensitive and searches for the full word string, so “i” will not be found and the function will return the number 0.
If ALPHA1 is an alpha series,
series stfind = @wrfind(alpha1, "did")
returns the last position of the string word “did” matching words in the string list values of ALPHA1 for each observation in the workfile sample.
If SVEC1 is an string vector,
vector stfind = @wrfind(svec1, "I")
returns the last position of the string word “I” matching words in the string lists in each element of SVEC1.
Cross-references
Find location of a word (not case-sensitive) in a string list searching from end.
Syntax: @wrfindnc(str_list, str_cmp)
str_list: string
str_cmp: string
Return: integer
Looks for last occurrence of the string str_cmp in the string list str_list, and returns the position in the list or 0 if the string is not in the list.
• This function is the non-case-sensitive version of the
@wrfind function.
• Note that this function works only on single words; for multiple or partial words, use
@rinstr.
Examples
= @wrfindnc("I did it. Did you?", "DID")
returns the number 4, indicating the last caseless string “did” is 4th in the list.
= @wrfindnc("I did not do it. I left early.", "i")
returns the number 6, since the last “i” or “I” word was in the 6th position.
If ALPHA1 is an alpha series,
series stfind = @wrfindnc(alpha1, "did")
returns the last position of the string word “did” caselessly matching the string list values of ALPHA1 for each observation in the workfile sample.
If SVEC1 is an string vector,
vector stfind = @wrfindnc(svec1, "I")
returns the last position of the string word “I” caselessly matching words in the string lists in each element of SVEC1.
Cross-references
Right-most words of a string list.
Syntax: @wright(str_list, n)
str_list: string
n: integer
Return: string
Returns a string list containing the right n word elements of string list str_list. If the string list str_list is shorter than n elements, this function returns all of the elements in the source string.
Examples
The commands
string orig = "I did not do it"
string sc1 = @wright("I did not do it", 2)
string sc2 = @right(orig, 2)
return the string objects SC1 and SC2 containing the string “do it”.
If ALPHA1 is an alpha series,
alpha strrght = @right(alpha1, 3)
returns the right-most 3 words from the string values of ALPHA1 for each observation in the workfile sample.
If SVEC1 is an string vector,
svector strrght = @right(svec1, 2)
returns an svector containing 2 words from the left end of each element of SVEC1.
Cross-references
Sorted list of words in a string list.
Syntax: @wsort(str_list[, “d”])
str_list: string
“d”: (optional) string literal
Return: string
Returns sorted elements of str_list. Use the “d” flag to sort in descending order.
Examples
@wsort("expr1 aa1 fr3")
returns the sorted string “aa1 expr1 fr3”
@wsort("fq8 Fq8 xpr1", "d")
sorts the string in descending order: “xpr1 Fq8 fq8”.
If ALPHA1 is an alpha series,
alpha a1 = @right(alpha1, 3)
returns the sorted string list values of ALPHA1 for each observation in the workfile sample.
If SVEC1 is an string vector,
svector s1 = @right(svec1, 2, "d")
returns an svector containing the descending order sorted string lists for each element of SVEC1.
Create string vector from words in a string list.
Syntax: @wsplit(str_list)
str_list: string
Return: svector
Returns an svector containing the elements of str_list.
Examples
If string list SS01 contains “A B C D E F”, then
svector s1 = @wsplit(ss01)
returns the svector S1, placing each word element of SS01 in a separate row, so that tow one of S1 contains “A”, row two contains “B”, etc.
The command
svector s2 = @wsplit("apples oranges pears")
creates a 3 element svector S2, with the rows containing “apples”, “orange”, and “pears”.
Cross-references
See also
@sfill. See
@wjoin for obtaining a string from an svector.
Union of words in two string lists.
Syntax: @wunion(str_list1, str_list2)
str_list1: string
str_list2: string
Return: string
Returns the elements that are in either str_list1 and str_list2. This function is case-sensitive.
Examples
@wunion("ABC DEF", "ABC G H def")
returns the string “ABC DEF G H def”. Each new element is added to the string list, skipping elements that have already been added to the list.
If ALPHA1 and ALPHA2 are alpha series,
alpha a1 = @wunion(alpha1, alpha2)
returns the union of values for elements of ALPHA1 and ALPHA2 for each observation in the workfile sample.
If SVEC1 and SVEC2 are string vectors,
svector s1 = @wunion(svec1, svec2)
returns an svector containing the union of the elements in SVEC1 and SVEC2 for each element of the svectors.
Cross-references
Remove duplicate words in a string list.
Syntax: @wunique(str_list)
str_list: string
Return: string
Returns str_list with duplicate elements removed from the list. This function is case-sensitive.
Examples
@wunique("fr1 fr2 fr1")
returns the string “fr1 fr2”. Note that this function is case-sensitive, such that
@wunique("a A b B c c")
returns the string “a A b B c”.
If ALPHA1 is an alpha series,
alpha a1 = @wunique(alpha1)
returns the unique string list values of ALPHA1 for each observation in the workfile sample.
If SVEC1 is an string vector,
svector s1 = @wunique(svec1)
returns an svector containing the unique string lists for each element of SVEC1.
Cross-references