BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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!
2 REPLIES 2
Cynthia_sas
Diamond | Level 26
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
deleted_user
Not applicable
Thank you,Cynthia, for your always informative reply! That was what we needed.

hackathon24-white-horiz.png

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.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 956 views
  • 0 likes
  • 2 in conversation