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.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.