Wednesday, April 18, 2012

SAS Macros Quick and useful TIP

HI Folks,

I have a quick tips for you on macros. Most of the code should be self explanatory, but do post comments if you need yelp/suggestion !

Scenario : you are testing some code in Windows SAS session using macros ! need help to see what all macro variables you had created and you wana clear them all (ofcourse just close the session and restart like an dork !)

use:
%put _all_; /* To see all kinds of macro variables that exist in session */

%put _global_ ; /* To only global macro variables that exist in session */
%put _local_ ; /* for local variables , if any */

but that was not tricky, but indeeed helpful.

use the macro ! to clear all global macro variables in a session (this will also clear all the automatic global variables but nothing important ):


COde
%let mymac1=Krypton;
%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;



Thanks,
Kr !!