Find out what SAS macro SAS will invoke

If you want to use WHICH, feel free to download it here:

Download which.sas


If you are not prompted to "Save To Disk", then right-click the link and choose "Save Link Target As..."  Otherwise, you will need to save the web page to your computer.  Make sure you save the which.sas file as a plain text file not an htm/html file.


Disclaimer:  There is no warranty on this software either expressed or implied.  This program is released under the terms and conditions of GNU General Public License.



Programmer:  Dan Blanchette
The Carolina Population Center
The University of North Carolina
Chapel Hill, NC  USA

Date:  03Nov2009
Last updated:  09Dec2010

Find a SAS macro file in the directory it is stored on your computer:
%which(name of macro without the percent sign , options );


The WHICH SAS macro is like the Stata command (and UNIX/Linux command) which.  It looks in your SASAUTOS path for the location of a SAS macro that SAS will automatically find when:  %macroname is used in SAS code and then it will print the first 10 lines of the macro in your log window/file.

In UNIX/Linux you can add directories of other locations of SAS macros that SAS will automatically find when %macroname is used in SAS code by putting a file named: sasv9.cfg in your home directory and putting this line in it:
-sasautos ( '!SASROOT/sasautos' '$HOME/SASmacros/' )

NOTE:  It is best to add your personal directories after:  '!SASROOT/sasautos' so that SAS will work normally for you in case you put a SAS program file that's named the same as a SAS macro that is installed with SAS like:  lowcase.sas.

options mautolocdisplay; will display in the log the path to the SAS program and the file name that contains the autocall macro whenever that macro is invoked.

%which(macro_name); will show all macros named macro_name that are compiled and in any of the directories specified SASMSTORE option libref in the order they will be invoked by SAS.  SAS will only use the first macro named macro_name that SAS finds compiled in a concatenated library specified in the SASMSTORE option but WHICH will find and show all of them.  WHICH will also find and show all macros files named macro_name.sas in the directories specifed in the SASAUTOS system option but SAS will only use the first one that SAS finds.

The WHICH SAS macro can not be run in any version of SAS prior to version 9.


name of macro
Specifies the name of the SAS macro to look for.  Do not type the percent sign.

Print all lines of the macro (not just the first 10 lines which is the default).

How to use the WHICH macro

Using the WHICH SAS macro requires that you understand how to use the %include SAS statement and that you know how to call a SAS macro.
For example, if you have copied this file to "C:\SASmacros", then you tell SAS about this macro by adding the following line to your SAS program:
  %include "C:\SASmacros\which.sas"; 
The %include statement makes SAS aware of the WHICH macro which is in the file "which.sas".  To use the macro you have to make a call to it.  To do that you add a line like the following to your SAS program:
  %which(lowcase, full); 
The information inside the parentheses is passed on to the WHICH macro.


%include"C:\SASmacros\which.sas"; ** Include macro once in a SAS session and call it **;
                                   *  as many times as you like in that session.     **;


** print all lines of lowcase.sas: **;
%which(lowcase , full);

Wink Plone Theme by Quintagroup © 2013.

Personal tools
This is themeComment for Wink theme