Focal Point
substring and posit

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/2481009331

October 19, 2005, 01:51 PM
Pam Kratt
substring and posit
We need to find a value within a substring, so we're using posit. Our problem is we need to find the last occurence of the value within the substring and posit only finds the first occurence ... is there a simple way to do this?

For example our string we're looking for is le in the statement "middle length". We want to find the position of length.

Thanks.
October 19, 2005, 01:54 PM
Pam Kratt
another note: we actually want to search from the end instead of the beginning.
October 19, 2005, 02:09 PM
reFOCUSing
Here is two ways you can do it:

-SET &PINDX = 0;<br />-* Past Index.
<br />-SET &INDX  = 1;<br />-* Curent Index.
<br />-SET &SINDX = 1;<br />-* Start Index.
<br />-SET &EINDX = 5;<br />-* End Index.
<br />-SET &STR   = 'A';<br />-* Search String.
<br /><br />-* Thing report only needs the variable &STR.
<br />TABLE FILE CAR<br />PRINT
<br />  COUNTRY<br />COMPUTE
<br />  TEST00/A10 = LJUST(10,(REVERSE(10,(SUBSTR(10,(LJUST(10,(REVERSE(10,COUNTRY,
<br />    'A10')),'A10')),1,(POSIT((LJUST(10,(REVERSE(10,COUNTRY,'A10')),'A10')),10,
<br />    '&STR',1,'I3'))-1,10,'A10')),'A10')),'A10');
<br />-* you could use YRTNUOC and TEST01 to produce the same thing as TEST00.
<br />COMPUTE<br />  YRTNUOC/A10 = LJUST(10,(REVERSE(10,COUNTRY,'A10')),'A10'); NOPRINT
<br />COMPUTE<br />  TEST01/A10 = LJUST(10,(REVERSE(10,(SUBSTR(10,YRTNUOC,1,(POSIT(YRTNUOC,
<br />    10,'&STR',1,'I3'))-1,10,'A10')),'A10')),'A10');
<br />END
<br />-RUN<br />
<br />-* This report needs the variables &PINDX, &INDX, &SINDX, &EINDX and &STR.
<br />TABLE FILE CAR
<br />PRINT
<br />COUNTRY
<br />COMPUTE
<br />  CNTRY&PINDX/A10 = LJUST(10,COUNTRY,'A10'); NOPRINT
<br />-REPEAT :LOOP FOR &INDX FROM &SINDX TO &EINDX<br />COMPUTE
<br />  CNTRY&INDX/A10 = SUBSTR(10,CNTRY&PINDX,
<br />    (POSIT(CNTRY&PINDX,10,'&STR',1,'I3'))+1,10,10,CNTRY&INDX); NOPRINT
<br />-SET &PINDX = &INDX -1;
<br />-:LOOP
<br />-SET &INDX = &EINDX+1;
<br />COMPUTE
<br />  CNTRY&INDX/A10 = CNTRY&EINDX;
<br />END
<br />-RUN

This message has been edited. Last edited by: <Maryellen>,
October 19, 2005, 02:14 PM
mgrackin
We had a discussion like this earlier in the year on Focal Point. Do a search for the keyword REVERSE.

There were a number of suggestions on how to find the last instance of a value. The solution I recommended was to use the REVERSE function to reverse the string and then do a search for the value. In your case since you are looking for 'le' do not forget to reverse the value you are looking for ('el') since the string you will be searching will be reversed. After you reverse the string, use POSIT to find 'el' instead of 'le'. After reversing the string, the first instance will really be the last and the last shall be the first. (Hmmm, where have i heard that before?)

I hope this helps.
October 19, 2005, 02:35 PM
Pam Kratt
I searched for reverse but I couldn't find anything on the topic. Just knowing the keyword reverse may help.
October 19, 2005, 03:26 PM
mgrackin
I am on three discussion forums for IBI products. The discussion could have occured on another one of those forums. Sorry about that.