BookmarkSubscribeRSS Feed
Mike_Davis
Fluorite | Level 6

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

6 REPLIES 6
Haikuo
Onyx | Level 15

%let bbb=1;

%put %symexist(bbb);

%put %symexist(aaa);

Haikuo

Amir
PROC Star

Hi

Have you tried the %symexist macro function?

Regards,

Amir.

art297
Opal | Level 21

You could just add the /NOWARN option.

Astounding
PROC Star

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.

art297
Opal | Level 21

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;

Astounding
PROC Star

Art,

It doesn't get any better than that.  Good solution.

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 4051 views
  • 8 likes
  • 5 in conversation