End the %DO block. If the file could not be opened, the %ELSE is executed and a note
is written to the log.
%end;
%else %put &filename could not be open.;
End the macro definition. Invoke the macro by passing in the full pathname.
%mend FileAttribs;
%FileAttribs(c:aaa.txt)
Example 17: Delete All User-defined Macro
Variables
Details
This example retrieves all the user-defined global macro variables from the
SASHELP.VMACRO view and uses a programming technique with the %SYMDEL
function to delete these macro variables.
If running in SAS Enterprise Guide 4.3 or higher, this example also deletes the global
macro variable SASWORKLOCATION. A modification can be made to the IF statement
to keep this from happening. For more information about the modification, see comment
on page 478.
Program
%macro delvars;
data vars;
set sashelp.vmacro;
run;
data _null_;
set vars;
temp=lag(name);
if scope='GLOBAL' and substr(name,1,3) ne 'SYS' and temp ne name then
call execute('%symdel '||trim(left(name))||';');
run;
%mend delvars;
%delvars
Program Description
Begin the macro definition.
%macro delvars;
Create a data set called Vars that reads the SASHELP.VMACRO view that contains
information about currently defined macro variables. A data set is created from
SASHELP.VMACRO to avoid a macro symbol table lock.
Example 17: Delete All User-defined Macro Variables 477
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
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset