The macro primarily operates on macro variable names passed as parameters. For optional deletion of compiled macros, it queries the system view `dictionary.catalogs` (part of SASHELP) and manipulates the system's SAS catalogs.
1 Code Block
LANGAGE MACRO SAS
Explanation : This block uses macro language functions to iterate over a list of variable names (considered as base names for macro variable arrays). For each name, it deletes all indexed macro variables (e.g., `myArray1`, `myArray2`) as well as the special `LBOUND`, `HBOUND`, and `N` variables that define the bounds and size of the macro variable array. The `NOWARN` option prevents warnings from being displayed if a macro variable does not exist.
Explanation : This block is executed if the `macarray` parameter indicates that macros should be deleted. It uses `%sysfunc(dosubl(...))` to execute a SAS code block in submission mode. This block:
1. Uses `PROC SQL` to query the `dictionary.catalogs` view to identify compiled macros (`objtype = 'MACRO'`) in the `WORK` library whose names match those provided in `arrs`. The results are stored in a temporary table.
2. A step-by-step `DATA _NULL_` with `CALL EXECUTE` dynamically generates `PROC CATALOG` statements for each identified macro. `PROC CATALOG` is then used with the `force` option to delete the corresponding macro entries from the WORK catalog.
3. Finally, `PROC DELETE` deletes the temporary table created by `PROC SQL`.
Copied!
%if %qupcase(&macarray.) in (Y YES) %then
%do;
%let rc = %sysfunc(dosubl(
/*+++++++++++++++++++++++++++++++++++++++++++++*/
options nonotes nosource %str(;)
proc sql noprint %str(;)
create table _%sysfunc(datetime(), hex16.)_ as
select memname %str(,) objname
from dictionary.catalogs
where
objname in (%upcase(
%str(%")%qsysfunc(tranwrd(&arrs., %str( ), %str(%,%"))))%str(%")
))
and objtype = 'MACRO'
and libname = 'WORK'
order by memname %str(,) objname
%str(;)
quit %str(;)
data _null_ %str(;)
do until(last.memname) %str(;)
set _last_ %str(;)
by memname %str(;)
if first.memname then
call execute('proc catalog cat = work.'
!! strip(memname)
!! ' et = macro force;') %str(;)
call execute('delete '
!! strip(objname)
!! '; run;') %str(;)
end %str(;)
call execute('quit;') %str(;)
run %str(;)
proc delete data = _last_ %str(;)
run %str(;)
/*+++++++++++++++++++++++++++++++++++++++++++++*/
));
%end;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.