www.sas.com > SAS UK > In the Know Homepage Search | Contact Us    
SAS UK Newsletter Banner SAS - The power to know(tm)  

Deleting User-Defined Macro Variables from the Global Symbol Table


How can you ensure the correct values are stored at the time of running your code within your global macro variable symbol table?

You can now use the %SYMDEL macro function to delete user-defined macro variables from the global symbol table.

Note: The %SYMDEL function works only on GLOBAL macro variables.

This is important if your global variables are updated at any point e.g. in a loop. If you need to delete all user-defined macro variables from the global symbol table, then use the following macro. In the example below you will see that a macro variable called mymac1 is set a value of 'Dave'. Once this macro variable has been set, the macro delvars which uses the %symdel function is called. This immediately removes all user-defined global macro variables. To test that the global macro variable &mymac1 has been deleted we've used a %put statement which generates the error.

WARNING: Apparent symbolic reference MYMAC1 not resolved, which proves the macro variable no longer exists.

%let mymac1=Dave;
%put &mymac1;
%macro delvars;
      data vars;
          set sashelp.vmacro;
      run;
      data _null_;
          set vars;
          if scope='GLOBAL' then
              call execute('%symdel '||trim(left(name))||';');
      run;
%mend;
%delvars
%put &mymac1;

NB : This code will run correctly from SAS 8.2 onwards and has been tested on Windows, Unix and the OS/390 operating systems

Back