Download existmv.sas existmv.sasSubmit a comment

%macro existmv (macrovar);

  %* macrovar - name of macro variable to check for existence;
  %* emits
  %*  0 if macro variable is not found in SASHELP.VMACRO;
  %*  1 if macro variable is found in SASHELP.VMACRO;
  %* -1 if an error occurred;

  %* Richard A. DeVenezia 12/23/98;
  %* Note: if option NOTES and the macro variable is not found in
  %*       SASHELP.VMACRO by the where clause of the open statement
  %*       there will be a note in the log
  %*       NOTE: No observations were selected from data set SASHELP.VMACRO.
  %*       There is currently no way to circumvent this.
  %*;

  %local dsid;

  %let dsid = %sysfunc (open (SASHELP.VMACRO (where=(name=upcase("&macrovar") and scope ne "EXISTMV"))));

  %if &dsid %then %do;
    %sysfunc (attrn (&dsid, ANY));

    %let dsid = %sysfunc (close (&dsid));
  %end;
  %else %do;
        -1
  %end;

%mend existmv;