Hello,
I want to understand starting position parameter in find function.
data test;
xyz='She sells seashells? Yes, she does.';
startposexp=-22;
whereisShe_ineg22=find(xyz,'She','i',startposexp);
put whereisShe_ineg22=;
run;
In this example whereisShe_ineg22=14
, Why?
As i understand, because the start position is negative, we start at the end of the string and count 22 places, and get the character s. Then the function start search to left, and to right. Why? please see
Thank you
Your second description is right.
Absolute value of POSITION determines where to start the search. SIGN of position determines the direction to search. The result is always location when counting from left, and is always positive. (or zero when not found).
The -22 tells SAS to begin the search at the 22nd character starting from the right, which is the first s of "seashells". It then finds the string 'She' (ignoring case) beginning at character 14 of the string (which is in the inside of the word "seashells").
You are not understanding how it uses the absolute value when the starting position is negative.
The first place where 'she' appears when searching backwards from byte 22 is byte 14.
Does this picture help?
She sells seashells? Yes, she does. ----+----0----+----0----+----0----+ ^ ^ | +-> Position 22 +> Position 14
actually if you change the search string from SHE to YES you can see that appear to behave as if it truncated the string at that position and then searches from the end of the truncated string backwards. With a starting position of 24 or larger it finds YES when searching backwards. But it does not find it when starting in position 22 or 23.
Your second description is right.
Absolute value of POSITION determines where to start the search. SIGN of position determines the direction to search. The result is always location when counting from left, and is always positive. (or zero when not found).
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: