****************Update on 7/2/2015 I was informed by tech support that this works in SAS version 9.3 as a result of a glitch - it does not work in SAS 9.4****************************************
I know this is an old thread but I found it unanswered and then figured out a solution.
%macro _localvaltest ();
/*setting up a local macro variable and putting it into a dataset*/
%let localvar=1;
data new;
set sashelp.shoes;
local=&localvar;
run;
/*creating a set that contains currently defined macro variables*/
data vars;
set sashelp.vmacro;
run;
/*write local vars to the log*/
%put _local_;
%put localvar value is &localvar;
/*executing a null step that deletes local variables from the macro table*/
data _null_;
set vars;
if scope='_LOCALVALTEST' then call execute ('%symdel '||trim(left(name))||';');
run;
/*write local vars to the log after the delete - does not show any and comes back unresolved for second put*/
%put _local_;
%put localvar value is &localvar;
/*creating a new set that shows the local macro variable has been deleted by the previous step*/
data vars2;
set sashelp.vmacro;
run;
%mend;
%_localvaltest;
Message was edited by: Scott Moore; Updated to correct syntax error and add %put statemets.
Hi Scott,
I don't think that's a solution. I'm getting all kinds of errors, starting with the first comment which is missing a / at the end. So as posted everything except the last data step is commented out.
It would be quite surprising if you could trick %SYMDEL into deleting a local variable.
If you play with this more and it still looks like you have deleted a local macro variable, I woud suggest:
1. ) add %put _local_ ; before and after your deletion, to show the change
2. ) turn on options MPRINT and run the code in batch (so you know you have a clean session)
3. ) post the log from that session (showing both the macro definition and the execution.
Kind Regards,
--Q.
Couldn't figure out how to cut and paste from my SAS editor and ended up typing the reply, which is never a good idea. Fixed the problem and tested it's working properly.
If you have SAS/EG use Copy HTML Source to Clipboard then click HTML in "this" editor and past.
Do another test and make a global version of the local macro variable you are trying to delete. Which one gets deleted?
If I create a global version of the same variable, the scope in the sashelp.vmacro is global and it no longer meets the condition of if scope= '_LOCALVALTEST' so it does not get deleted. I'll edit the program one more time to %put the value of the macro variable and it will come back as unresolved for the second %put statement showing that the value has been deleted.
My EG install is broken and getting IT to reinstall is such a hassle that I just use the enhanced editor.
What about simply saying;
%let mvar=;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.