Do you periodically delete unneeded global macro variables? You should! It releases memory and keeps your symbol table clean. This macro language statement deletes global macro variables:
Suppose you have a gaggle of macro variables cluttering up your global symbol table, and you want to delete them all, but you don't want to type all their names. Unfortunately, this won't work:
Ending your SAS session will delete your macro variables, but that's too drastic.
So what's a macro programmer to do? Easy! Just submit this code!
Boom! All user-defined global macro variables are gone!
What?! You never heard of %DELETEALL? Of course you haven't! That's because I just made it up!
Here's the good news: You can steal it from me! Here you go:
The DELETEALL macro
%macro deleteALL; options nonotes; %local vars; proc sql noprint; select name into: vars separated by ' ' from dictionary.macros where scope='GLOBAL' and not name contains 'SYS_SQL_IP_'; quit; %symdel &vars; options notes; %put NOTE: Macro variables deleted.; %mend deleteALL;
- The NONOTES option prevents this note from appearing in the log:
NOTE: PROCEDURE SQL used (Total process time):
- The %LOCAL statement creates the local macro variable, VARS, with a null value.
- The SQL step populates the local macro variable, VARS, with the names of all user-defined global macro variables, except those with SYS_SQL_IP_ in their names.
- DICTIONARY.MACROS is a metadata table with one row per macro variable.
- The %SYMDEL statement deletes all user-defined global macro variables.
- The NOTES option restores notes to the log.
- The %PUT statement confirms that your macro variables have been deleted.
Be sure to save the DELETEALL macro in your stored compiled macro or autocall library for convenient access!
Programming Courses from SAS
Want to learn more great tips like these? Consider taking a course in our SAS programming learning path.