data vars;
set sashelp.vmacro;
run;
Within a DATA step, the data set Vars that contains the macro variable names is
referenced in the SET statement. The LAG function is used to retrieve the previous value
of the name and then assigns it into a data set variable called Temp. Long macro
variables will span across multiple observations within the view. This technique is used
to assure the unique values.
data _null_;
set vars;
temp=lag(name);
Use an IF statement to make sure the following occurs:
• the scope of the macro variable is GLOBAL
• the first three characters do not begin with SYS since macro variables beginning with
'SYS' are reserved for use by the SAS system.
• Temp is not equal to the previous value
If these three items are true, use the CALL EXECUTE routine to build the %SYMDEL
statement with the name of the macro variable to be deleted. End the DATA step with a
RUN statement. Invoke the macro.
if scope='GLOBAL' and substr(name,1,3) ne 'SYS' and temp ne name then
call execute('%symdel '||trim(left(name))||';');
run;
%delvars
/* Change for SAS Enterprise Guide 4.3 users if you want to preserve the */
/* SASWORKLOCATION macro variable if scope='GLOBAL' and substr(name,1,3) */
/* ne 'SYS' and temp ne name and upcase(name) ne SASWORKLOCATION then call */
/* execute('%symdel '||trim(left(name))||';'); */
478 Appendix 5 • SAS Macro Examples