07-27-2012 10:40 AM
Sometime I don't know whether there was a macro variable in the SAS environment and I want to delete it .It will show me a warning message if the macro variable not exist when I trying to delete it.
%SYMDEL aaa bbb; /*try to delete aaa and bbb,but aaa is not exist*/
"WARNING: Attempt to delete macro variable aaa failed. Variable not found."
My question is ,To avoid the warning message.How to check whether a macro variable exist before delete it?
07-27-2012 03:56 PM
Presumably, you must be asking about open code. Otherwise if you were talking about inside a macro, you could just use %SYMEXIST, as suggested by others:
%if %SYMEXIST(aaa) %then %SYMDEL(aaa);
Since %IF is not permitted in open code, here's a way around that:
I'm not sure if I have the syntax exactly right here, but the approach should work easily enough. If you have a series of macro variables to delete, you would need to replace the WHERE statement:
if upcase(name) = 'AAA' then call execute('%symdel(aaa);');
else if upcase(name)='BBB' then call execute('%symdel(bbb);');
If you need to apply this to a long series of macro variable names, you might as well write a macro and stick with %symexist / %symdel.