This macro will return a yes or no depending on whether a macro has been compiled within the current SAS session. The way the code is currently written it will only work for those macros that have been compiled to the WORK.SASMACR catalog.
Pass in the name of the macro (minus the percent sign) you are searching for.
If the SAS session is created by a workspace server or running Enterprise Guide (EG)connecting through a server the macro code will need to be modified.
Currently the PROC CATALOG within the macro is looking in the SASMACR catalog but if running through a server the macros may be compiled and stored in a SASMACx catalog (where x represents 1,2,...). The code change would look something like this:
proc catalog cat=work.sasmac1; contents out=new(keep=name); run;
Starting in SAS 9.3 there will be a new function that will replace the technique described in this sample. It will be called %SYSMACEXIST.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
%macro test(name);
%global val;
proc catalog cat=work.sasmacr;
contents out=new(keep=name);
run;
data _null_;
set new;
if upcase(name) = "%upcase(&name)" then do;
call symput('val','yes');
stop;
end;
else call symput('val','no');
run;
%mend test;
/* Check for the existence of the macro test */
%test(test)
%put Does test exist: &val;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Output from log Does test exist: yes
Type: | Sample |
Date Modified: | 2010-07-09 11:27:38 |
Date Created: | 2009-06-25 13:02:33 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | Base SAS | z/OS | ||
OpenVMS VAX | ||||
Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
Microsoft Windows XP 64-bit Edition | ||||
Microsoft® Windows® for x64 | ||||
OS/2 | ||||
Microsoft Windows 95/98 | ||||
Microsoft Windows 2000 Advanced Server | ||||
Microsoft Windows 2000 Datacenter Server | ||||
Microsoft Windows 2000 Server | ||||
Microsoft Windows 2000 Professional | ||||
Microsoft Windows NT Workstation | ||||
Microsoft Windows Server 2003 Datacenter Edition | ||||
Microsoft Windows Server 2003 Enterprise Edition | ||||
Microsoft Windows Server 2003 Standard Edition | ||||
Microsoft Windows Server 2008 | ||||
Microsoft Windows XP Professional | ||||
Windows Millennium Edition (Me) | ||||
Windows Vista | ||||
64-bit Enabled AIX | ||||
64-bit Enabled HP-UX | ||||
64-bit Enabled Solaris | ||||
ABI+ for Intel Architecture | ||||
AIX | ||||
HP-UX | ||||
HP-UX IPF | ||||
IRIX | ||||
Linux | ||||
Linux for x64 | ||||
Linux on Itanium | ||||
OpenVMS Alpha | ||||
OpenVMS on HP Integrity | ||||
Solaris | ||||
Solaris for x64 | ||||
Tru64 UNIX |