Chang’s solution worked perfectly when I ran the code.
On a side note, I naively thought that I could create a simpler solution that avoided Perl regular expressions by using the compress function with the a and d modifiers. Once I started working on this problem, however, my solution quickly became more complicated than Chang’s, plus it still doesn’t work correctly. I’m hoping that someone can help me understand what exactly went wrong in my solution.
I attempted to create a macro variable called ALPHA_NUMERIC that would resolve to either Yes or No depending on the value of the macro variable STR. Here is the assignment statement I tried to use:
[pre]
%let alpha_numeric = %sysfunc(ifc(%nrbquote(%sysfunc(compress(%superq(str), , ad))) = , Yes, No));
[/pre]
It actually works for the first two examples from Chang’s posting:
[pre]
1 %let str=ABC123;
2 %let alpha_numeric = %sysfunc(ifc(%nrbquote(%sysfunc(compress(%superq(str), , ad))) = , Yes,
2 ! No));
3 %put str=%superq(str) alpha_numeric=&alpha_numeric;
str=ABC123 alpha_numeric=Yes
4
5 %let str=AB!C;
6 %let alpha_numeric = %sysfunc(ifc(%nrbquote(%sysfunc(compress(%superq(str), , ad))) = , Yes,
6 ! No));
7 %put str=%superq(str) alpha_numeric=&alpha_numeric;
str=AB!C alpha_numeric=No
[/pre]
However, it does not work for the third example:
[pre]
8 %let str=%str(%');
9 %let alpha_numeric = %sysfunc(ifc(%nrbquote(%sysfunc(compress(%superq(str), , ad))) = , Yes,
9 ! No));
ERROR: Argument 1 to function IFC referenced by the %SYSFUNC or %QSYSFUNC macro function is not a
number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution
of %SYSCALL statement or %SYSFUNC or %QSYSFUNC function reference is terminated.
10 %put str=%superq(str) alpha_numeric=&alpha_numeric;
str=' alpha_numeric=
[/pre]
I really don’t understand the first error message. It seems to me that the condition in the ifc function would clearly be false. I would have thought that the condition would be analogous to %eval(%str(%')= ), which SAS evaluates as 0.
I know that this error can easily be remedied by using macro %if %then logic or data step logic in conjunction with call symput. I would just like to know, for my own understanding, exactly why the above code fails.
Thanks.