If your example is of all the lines you need to read (unlikely I suspect) then perhaps:
data example;
string='<a href="a213w9245992999Vrh" target="_blank">PROPER DATA</a>';
want = scan(string,2,'<>');
run;
SCAN will allow you to provide characters that delimit string values. Since your line starts with an < then it precedes the first string which would be everything until the next < or > character.
You would want to assign a length to the target variable, Want above, to hold the longest expected value prior to use.
I would expect strange results. Your use of
nos2-1-nos2)
Would tent to always result in a value of -1. ( nos2-1-nos2 is equivalent to nos2-nos2-1) Which when you get negative lengths SUBSTR tends to odd things as documented in the online help:
Interaction
If length is zero, a negative value, or larger than the length of the expression that remains in string after position, SAS extracts the remainder of the expression. SAS also sets _ERROR_ to 1 and prints a note to the log indicating that the length argument is invalid.
There should be notes in the log.
@RandoDando wrote:
I have a raw data file which is importing some text columns with tags on either side of the data. The tags are not exactly the same on the left side for each case, and include no space. An example would be this:
<a href="a213w9245992999Vrh" target="_blank">PROPER DATA</a>
I want to extract from that PROPER DATA.
The alphanumeric portion after href= on the left side can vary from row to row.
I've tried this, but it does nothing.
pos1=findc(StringVar, '>');
pos2=findc(StringVar, '</a>');
NewVar = substr(StringVar, nos1+1, nos2-1-nos2);
I've tried this and had some result. No change.
pos1=findc(StringVar, '_blank">');
pos2=findc(StringVar, '</a>');
NewVar = substr(StringVar, nos1+1, nos2-1-nos2);
How can I extract that text?
... View more