I cannot figure out what you are trying to do.
You are running a DO loop based on the number of words in the string using COUNTW() with the default set of delimiters:
If your computer uses ASCII characters, the default delimiters are as follows:
blank ! $ % & ( ) * + , - . / ; < ^ |
But later you are calling the %SCAN() with just two characters as delimiter, space and double quote.
Also why are you having the macro generate SAS statements? Are you calling this macro in the middle of a DATA step or some other context where an IF statement makes sense?
And the IF statement you are generating also looks a little strange.
if index(%scan(&list_debug.,&d.," "),''') > 0
then %scan(&list_debug.,&d.) = tranwrd(%scan(&list_debug.,&d.),'''," ")
;
It seems to be assuming that the next word in the list is a valid SAS variable name. (but notice that the variable using the IF condition is potentially different than the variable used in the generated assginment statement because using different delimiters in the %SCAN() calls).
So I think you are trying to generate a statement like this:
if index(A,''')>0 then A=tranwrd(A,''',' ');
Which you does not need to IF, if the string is not found then tranwrd() already does nothing.
A=tranwrd(A,''',' ');
If also want to convert actual single quotes instead of just the HTML command to generate a single quote you can use:
A=tranwrd(tranwrd(A,''',' '),"'",' ');
... View more