Published on :
Macro CREATION_INTERNE | SASHELP

Deletion of macro variables and macros

This code is also available in: Deutsch Español Français
Attention : This code requires administrator privileges.
This macro, named `bdeleteMacArray`, is designed to manage the deletion of SAS© elements. It takes a list of macro variable prefixes (`arrs`) and uses them to delete indexed macro variables (`arr.J`) as well as boundary variables (`LBOUND`, `HBOUND`, `N`) associated with each macro variable 'array'. Optionally, if the `macarray` parameter is set to 'Y' or 'YES', the macro extends its functionality to search for and delete corresponding compiled macros in the WORK catalog, identified via the `dictionary.catalogs` view and deleted using `PROC CATALOG`. This process involves SAS© system administration tasks.
Data Analysis

Type : CREATION_INTERNE | SASHELP


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.
Copied!
1%local I J rc;
2%DO I = 1 %to %sysfunc(countw(&arrs.));
3%let arr = %scan(&arrs., &I., %str( ));
4 %DO J = &&&arr.LBOUND %to &&&arr.HBOUND;
5 /*%put *&arr.&J.*;*/
6 %symdel &arr.&J. / NOWARN;
7 %END;
8 %symdel &arr.LBOUND &arr.HBOUND &arr.N / NOWARN;
9%END;
2 Code Block
PROC SQL, DATA STEP, PROC CATALOG, PROC DELETE
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!
1%IF %qupcase(&macarray.) in (Y YES) %THEN
2 %DO;
3 %let rc = %sysfunc(dosubl(
4 /*+++++++++++++++++++++++++++++++++++++++++++++*/
5 options nonotes nosource %str(;)
6 PROC SQL noprint %str(;)
7 create TABLE _%sysfunc(datetime(), hex16.)_ as
8 select memname %str(,) objname
9 from dictionary.catalogs
10 where
11 objname in (%upcase(
12 %str(%")%qsysfunc(tranwrd(&arrs., %str( ), %str(%,%"))))%str(%")
13 ))
14 and objtype = 'MACRO'
15 and libname = 'WORK'
16 order by memname %str(,) objname
17 %str(;)
18 quit %str(;)
19 data _null_ %str(;)
20 do until(last.memname) %str(;)
21 set _last_ %str(;)
22 by memname %str(;)
23 
24 if first.memname then
25 call execute('PROC CATALOG cat = work.'
26 !! strip(memname)
27 !! ' et = macro force;') %str(;)
28 call execute('delete '
29 !! strip(objname)
30 !! '; RUN;') %str(;)
31 end %str(;)
32 call execute('QUIT;') %str(;)
33 RUN %str(;)
34 PROC DELETE DATA = _last_ %str(;)
35 RUN %str(;)
36 /*+++++++++++++++++++++++++++++++++++++++++++++*/
37 ));
38 %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.