Hi Guys,
Good Moring
data nth_occurance;
c='who is this' ;
run;
in the above string how to find 'is' 2nd occurrence position with out using any regex
Beats me why you do not want to use REGEX. But here is a solution using the FIND function:
data want;
set nth_occurance;
pos=-1; /* 1-length(search string) */
do _N_=1 to 2; /* N=2, here */
pos=find(c,'is',pos+2); /* add length(search string) to starting position */
if pos=0 then leave;
end;
run;
The program returns a POS value of 0 if the nth occurrence is not in string.
Hi,
The find() function can accept an argument for the starting position for the search, so you can search for the first occurrence and then look for the 2nd occurrence after that. See code below for an example.
data nth_occurance;
c = 'who is this';
pos = find(c,'is',find(c,'is') + 1);
run;
Thanks & kind regards,
Amir.
BTW your question is very unclear. What do you want to find?
Hi Kurt
I want to find 2nd occurrence position ' is' in that text
@BrahmanandaRao wrote:
Hi Kurt
I want to find 2nd occurrence position ' is' in that text
Just reposting what you already said won't help. Answer my questions.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.