05-29-2014 02:39 PM
I have a variable that is character that is comprised by various words like "ING Funds Trust: Ing Arbondel International bond Fund; Class A Shares". I want a command that searches these words and signals whether they contain specific words. For example, i want to to search for the word "bond". Notice that the word Arbondel contains bond but i am not interested in that. I only want SAS to flag the standalone "bond" word. I have experimented with various functions but cannot get exactly what i want. Any help would be very appreciated. Many thanks. Costas
05-29-2014 03:01 PM
It sounds like you are trying the INDEX function. There are some newer functions that may do exactly what you want, such as INDEXW or FINDW. Or, you can do it the old-fashioned way (adding a leading and trailing blank):
if index(' ' || string || ' ', ' bond ') then do;
05-30-2014 12:11 PM
One more question
Suppose i am looking for the word growth, and my string variable is called fund_name.
I am using this below:
When word equals "AMERICAN PENSION INVESTORS TRUST: GROWTH FUND" the code works fine.
But when it equals "API TRUST:GROWTH FUND" it does not.
I think this is because there is no gap between : and GROWTH.
is there a solution to this? Note that i cannot include all the trailing characters (i.e., TRUST) because these are different in different rows.
The quest continues....
thanks a lot to all for the help
05-30-2014 01:20 PM
FindW considers blank as a default delimiter. If you have : in your text then we need to tell the FINDW fucntion treat this as a delimiter. Try the code given below. Hope this will solve the problem.
word1="AMERICAN PENSION INVESTORS TRUST: GROWTH FUND";
word2="API TRUST:GROWTH FUND";
proc print data=have;
Need further help from the community? Please ask a new question.