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
SAS Super FREQ
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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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