SUPPORT / SAMPLES & SAS NOTES
 

Support

Sample 36360: How to determine whether a macro exists within a SAS session

DetailsCodeOutputAboutRate It

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.