DATA Step, Macro, Functions and more

find exact match in a text string

Accepted Solution Solved
Reply
Regular Contributor
Posts: 180
Accepted Solution

find exact match in a text string

[ Edited ]

Hi!  

 

I have string values with

Cycle 1 Day 1

Cycle 1 Day 15

Cycle 2 Day 1

.

.

Cycle 23 Day 1

Cycle 23 Day 15

 

I want to output 'Day 1' observations regardless of cycle.  Using index, is outputting a Day 15's as well since it 'contains' Day 1.

 

data want
set have
if index(visit, "Day 1") then do;
cycle = input(scan(VISIT, 2), 3.);

end;
if cycle ne ''  ;
run;

 

 

Help is appreciated!

 


Accepted Solutions
Solution
‎01-30-2018 04:12 PM
Super User
Posts: 22,845

Re: find exact match in a text string

Why not just grab the number at the end using SCAN(string, 4) and check if that equals 1?

View solution in original post


All Replies
Solution
‎01-30-2018 04:12 PM
Super User
Posts: 22,845

Re: find exact match in a text string

Why not just grab the number at the end using SCAN(string, 4) and check if that equals 1?

Regular Contributor
Posts: 180

Re: find exact match in a text string

I was totally overthinking it! Thank you!
Super User
Posts: 13,029

Re: find exact match in a text string

Or try

 

if findw(visit, "Day 1") then ...

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 204 views
  • 0 likes
  • 3 in conversation