Hi All
Is it possible to find the position of a character in a text like these examples
Text | Need_Position_of_4 | Result |
123412344444 | 3 | 9 |
1112222223400120044444 | 2 | 18 |
For the first example I need 3th 4 and the second one I need the second 4.
Using FINDC you can search "Need Position of 4" number of times as follows.
What is logic, i.e. why is it to find the first, or the second? Post some test data in the form of a datastep, and required output, with an explanation of what you require. If you want search functions (and you can find these out from the help documentation or google them): find, findw, findc, index etc.
data Have;
input Text : $ 20.;
cards;
123412344444
1112222223400120044444
;
data Want;
set Have;
if _n_=1 then do;
Need_Position_of_4 = 3;
Result = findc(Text,'4',findc(Text,'4',index(Text,'4')+1)+1);
end;
else do;
Need_Position_of_4 = 2;
Result = findc(Text,'4',index(Text,'4')+1);
end;
run;
proc print ;run;
Using FINDC you can search "Need Position of 4" number of times as follows.
Thank you so much for your answer. it is very helpful.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.