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.

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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