BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ChickenLittle
Obsidian | Level 7

Hi,

 

I have a field with a string of numbers separated by semicolons. I want to check if any of the numbers between the semicolons in this field is a match to what I am looking for. I know I can use "index" or "find," but it may give a false positive if it is a small number within a larger number. For example, if I have a field that contains 123;654;89 and I want to know if it contains '54', I do not want a false positive since 54 is in 654. How can I do this?

 

Example of what I have:

Obs     StrgOfNum

1          934;54;1234

2          123;6542;89

 

What I want is to know if the number 54 is in any of the observations:

Obs    

1 <---Should return a positive output indicated it is in this observations

2 <---Should return a negative output indicating it is not in this observations

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star
data have;
   string = '934;54;1234';
   found = findw(string, '54');
   output;
   put _all_;
   string = '123;6542;89';
   found = findw(string, '54');
   output;
  put _all_;
run;

View solution in original post

2 REPLIES 2
SASKiwi
PROC Star
data have;
   string = '934;54;1234';
   found = findw(string, '54');
   output;
   put _all_;
   string = '123;6542;89';
   found = findw(string, '54');
   output;
  put _all_;
run;

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

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 994 views
  • 0 likes
  • 2 in conversation