Command Reference : String and Date Function Reference
  
 
@wkeep
Keep words in string list.
Syntax: @wkeep(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
See also @wdrop, @wnotin, @wunique.