On the left of an assignment the length of the affected variable is already set. Would "ONE ABC TWO" be replaced by "ONE D TWO" or "ONE D TWO" ? What if the replacement string is longer than the original?
Thank you SAS geniuses for helping folks like me learn more, yep the length is perhaps the factor that makes the case
data _null_;
varname="ONE ABC TWO";
if scan(varname, 2) = 'ABC' then call scan(varname, 2, position, length);
substr(varname,position,length)='D';
put varname=;
run;
@PGStats Sir, your reasoning makes me learn more and more. Merci beacoup!
Perhaps this could be an enhancement to TRANWRD with an additional option to indicate replace the "nth occurrence only" instead of the default replace all occurences. Maybe a selection of options similar to Findw for things like start nth occurrence to end nth occurrence, work from right to left instead of left to right, whole words only, case sensitive/insensitive.
@data_null__ Thank you Sir aka guru of all. I am still learning by reading a lot of your posts. I wish you posted here more often or I should have retained my SAS L account. Have a great afternoon
The behavior that you are looking for is available now through the PRX functions. That said, I can definitely see the benefit of having a function like this available. I'll enter the suggestion.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.