Desktop productivity for business analysts and programmers

How to determine values at specific locations`

Reply
N/A
Posts: 0

How to determine values at specific locations`

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%' ?

Thank you in advance!
SAS Super FREQ
Posts: 8,721

Re: How to determine values at specific locations`

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.

cynthia
N/A
Posts: 0

Re: How to determine values at specific locations`

Thank you,Cynthia, for your always informative reply! That was what we needed.
Ask a Question
Discussion stats
  • 2 replies
  • 98 views
  • 0 likes
  • 2 in conversation