Using the LIKE operator in Proc Sql, is there a way to determine if certain values exist in a field at a certain location? Example, I want to determine if the value XYZ exists in a field, starting at position 4. Such as, AAAXYZ, ABCXYZ, DEFXYZ, GHIWWW, JKLTTT, MNOXYZ.
Would I use something like this: IF Field LIKE '%%%XYZ%' ?
Hi:
If you look in the SAS documentation for the LIKE operator, you will find that the percent sign (%) is the wild card indicator for any number of characters, while the underscore (_) is the wild card indicator for a SINGLE character.
You will need to be careful with your comparison because there is a difference between having a % at the end of the quoted string
[pre]
where charvar like '___XYZ'; /* 3 underscores */
where charvar like '___XYZ%'; /* 3 underscores XYZ % */
[/pre]
depending on whether your character variable is EXACTLY 6 characters long or is greater than 6 characters.