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.
Thank you,Cynthia, for your always informative reply! That was what we needed.
The 2025 SAS Hackathon Kicks Off on June 11!
Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.