Hello everyone,
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.
%let bbb=1;
%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?
Thanks
Mike
%let bbb=1;
%put %symexist(bbb);
%put %symexist(aaa);
Haikuo
Hi
Have you tried the %symexist macro function?
Regards,
Amir.
You could just add the /NOWARN option.
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:
data _null_;
set sashelp.vmacro;
where upcase(name)='AAA';
call execute('%symdel(aaa);');
run;
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.
Good luck.
In case my previous message wasn't sufficiently clear, I think the following does exactly what you want:
%let bbb=1;
%SYMDEL aaa bbb /NOWARN;
Art,
It doesn't get any better than that. Good solution.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.