Got a complex macro?  Don’t have time to work out what it is actually doing?  Its much easier to work with resolved code!  The macro below will help – just stick it at the start of your code, and write the resolved code somewhere else (which can then be ‘stepped through’ to understand whats going on).

%macrox/* mfile will only work if its inside a macro! */     
      %letloc=c:tempMyResolvedCode.txt;
      %letrc = %sysfunc(filename(fref,&loc));
      %letrc = %sysfunc(fdelete(&fref)); 
      filename mprint “&loc”lrecl=2048;
      options mfile mprint ;
      data _null_;
      if _n_=1then call execute(“Data _null_;”);
      set sashelp.vlibnam(where=(substr(libname,1,3) ne ‘SAS’));
      if cats(libname,path) ne unique then
        call execute(‘comment Find&ReplaceMe libname ‘||libname||‘ “‘||trim(path)||‘”;’);
      retain unique;  unique=cats(libname,path);
      run;run; /* this bit retrieves the relevant libraries, without executing anything.. */
%mend;  %x

Points to note:

  • If your macro is data driven, the code above may change depending on the data!
  • The delete function does not  always work (eg if your SAS session still has the file open)
  • The comment feature is very old!  Credit to James Taylor for knowing about this.
  • You may find for practical use, all you really need is this:
filenamemprint “c:tempMyResolvedCode.txt”lrecl=2048;
options mfile mprint ;