Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

looking for a pattern within a string (which is not a string )

Status
Not open for further replies.

iren

Technical User
Mar 8, 2005
106
US
Hi!

I have a field Comments in my source file. This field contains some keywords which I need as criteria but unfortunately they are not located in a strong order (kind of a mess):

For Example
_________________________________________________
COMMENTS
____________________________________________________
Keyword1
Keyword2
Keyword1 keyword3
……………………….
…………………………..
keyword1 keyword5 keyword6



Should it be fixed width values , I would knew how to find a pattern in strings like the following:
Comments=’keyword%’

However actually the value of this field is partly empty and partly COMMENTS field is populated out of order and I do not think I can look for the pattern(keyword) within "empty" string

… Is there any way to overcome the issue in order I could use keywords criteria along with my other fields value?

Thank you!

Iren

 
If you extract the entire comments field into a single SAS string variable, then you should be able to use the standard text string search functions such as INDEX, INDEXC or INDEXW.
I'm not sure that I understand what you mean by "partly empty", but that shouldn't hinder use of SAS functions..

You can also lookup RXMATCH and RXPARSE. These are tricky functions to use, but very powerful. If oyu have SAS Version 9, there are some new pattern matching functions available as well.
 
Chris,
Saying "partly empty" I meant that the COMMENTS field might be empty OR keyword1,2,3,.. may not start at position 1 of the field. Does it matter when I use any of the functions or "keyword%" technique?


I use version 8....

Looking at Index, indexc function I found out that they give me a chance to find only a location of the search while I need a whole word...

data temp4;
set temp3;
found = indexc(string, "-", "_", "X");
found1 = index(string, "-_X");
run;

proc print data = temp4;
run;
Obs string found found1

1 4-5 abc XxX 2 0
2 11_ jkl xxx 3 0
3 abc 3-5 jjj 6 0
4 xXx ()1 lll 2 0
5 xxx 344 aaa 0 0

Iren
 
Irene,
What Chris meant by using the above functions was once you put the entire string into a sas string you can work with it in SAS. Let me explain, the index(c) function returns an index of where that subtring exists in the larger string. We are assuming that you know your keywords in advance. You can now tell if the keyword exists in your comment, because if it does the function returns the index, a positive number.
So, if you are looking for "keyword1" in your string you would do the following:

if (index(your_comment_string,"Keyword1") gt 0 ) then
flag=1;

I hope that this has helped you.
Klaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top