DATA Step, Macro, Functions and more

Finding Location of SAS Macros

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

Finding Location of SAS Macros

I have been going through SAS code written by others, which references a number of macros in folders around a large corporate network and I don't really know what many of these functions do. Is there a way of locating where SAS is finding the code for an individual function.

 

So if I put in a macro name for example rather than carrying out the instructions of the macro it would tell my the file path to where the code is located.

 

Thanks


Accepted Solutions
Solution
‎08-22-2016 11:45 PM
SAS Super FREQ
Posts: 683

Re: Finding Location of SAS Macros

Hi

 

Have a look the MAUTOLOCDISPLAY SAS System Option.

 

When you call an autocall macro, it will display the location of the code.

 

Also have a look at other macro related SAS System Options here http://support.sas.com/documentation/cdl/en/allprodslang/68037/HTML/default/viewer.htm#syntaxByCateg...

 

 

Bruno

View solution in original post


All Replies
Trusted Advisor
Posts: 1,374

Re: Finding Location of SAS Macros

run PROC OPTIONS and look for SASAUTOS in the log.

It may give you a hint where to search the macro.

 

Shmuel

 

Solution
‎08-22-2016 11:45 PM
SAS Super FREQ
Posts: 683

Re: Finding Location of SAS Macros

Hi

 

Have a look the MAUTOLOCDISPLAY SAS System Option.

 

When you call an autocall macro, it will display the location of the code.

 

Also have a look at other macro related SAS System Options here http://support.sas.com/documentation/cdl/en/allprodslang/68037/HTML/default/viewer.htm#syntaxByCateg...

 

 

Bruno

Occasional Contributor
Posts: 9

Re: Finding Location of SAS Macros

Thanks bruno this seems to work

Super User
Posts: 9,676

Re: Finding Location of SAS Macros

I remember @Tom has already post a solution for someone, Ask him.


%let x=%sysfunc(pathname(sasautos));

%put &x ;

Super User
Super User
Posts: 6,499

Re: Finding Location of SAS Macros

If you are using autocall macros I have a program that you can run at the end of your program that will read the list of compiled macros from WORK.SASMACR and try to find corresponding files in the SASAUTOS paths that match the macro names.

 

So if you can re-run your complicated program and then call this at the end you can get a report of which macros the program called.  

 

For this to work you need to use autocall macros and not stored compiled macro catalogs.  Also you need to be careful to define only one macro in each source code file in your autocall library.  Also if you have a complicated program with conditional branches it will only find the macros that were actually called. It won't find any that the code might use in branches of the code that did not run.

 

 

 

%macro maclist
/*----------------------------------------------------------------------
Generate list of compiled macros and their source directories
----------------------------------------------------------------------*/
(out=maclist   /* Name of dataset to generate */
,dlist=        /* Directory list to scan (default=SASAUTOS option) */
);
/*----------------------------------------------------------------------
Produce a summary dataset with the location of the source file for the
compiled macros currently in SASHELP.SASMACR catalog by scanning across
SASAUTOS search path to see if corresponding file exists.

When using SAS 9.2 or higher it will use to Q modifier on the SCAN()
function to allow pathnames to include parentheses when properly quoted.

----------------------------------------------------------------------*/

data &out ;
  attrib MACRO length=$32  label='Macro name';
  attrib FOUND length=3    label='Found? (0/1)';
  attrib FILE  length=$36  label='Filename';
  attrib DNAME length=$200 label='Directory name';
  keep macro found file dname;

  if _n_=1 then do;
*----------------------------------------------------------------------;
* Get SASAUTOS option into string variable and copy individual paths ;
* into DLIST, expanding any filerefs that are found (such as SASAUTOS).;
*----------------------------------------------------------------------;
    length dlist autos path $32767 ;
    retain dlist ;
%if %length(&dlist) %then %do;
    autos=%sysfunc(quote(&dlist));
%end;
%else %do;
    autos=getoption('sasautos');
%end;
    do i=1 by 1 until (path= ' ');
%if %sysevalf(9.2 <= &sysver) %then %do;
      path=scan(autos,i,'( )','q');
%end;
%else %do;
      path=scan(autos,i,'( )');
%end;
      if length(path) <= 8 then do;
        if 0=fileref(path) then path=pathname(path) ;
      end;
      dlist=left(trim(dlist)||' '||path);
    end;
  end;

  set sashelp.vcatalg;
  where libname='WORK' and memname='SASMACR'
    and memtype='CATALOG' and objtype='MACRO';
  macro=objname;
  file=lowcase(trim(macro))||'.sas';

*----------------------------------------------------------------------;
* Scan through the paths in DLIST until file found or end of list ;
*----------------------------------------------------------------------;
  found=0;
  done=0;
  do i=1 by 1 until (found or done);
%if %sysevalf(9.2 <= &sysver) %then %do;
    dname=dequote(scan(dlist,i,'( )','q'));
%end;
%else %do;
    dname=dequote(scan(dlist,i,'( )'));
%end;
    if dname=' ' then done=1;
    else if fileexist(trim(dname)||'/'||trim(file)) then found=1;
  end;
  if ^found then dname=' ';
run;

%mend maclist;
SAS Super FREQ
Posts: 683

Re: Finding Location of SAS Macros

Hi

 

Also have a look at the MAUTOLOCINDES SAS System Option.

 

Here is what the doc says:

Specifies whether the macro processor prepends the full pathname of the autocall source file to the description field of the catalog entry of compiled autocall macro definition in the Work.SASMacr catalog.

 

Bruno

Occasional Contributor
Posts: 9

Re: Finding Location of SAS Macros

Thanks for the program Tom it'd be good to run on large programs.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 1048 views
  • 5 likes
  • 5 in conversation