I have a program (it was developed by my colleagues) with 20 paths in SASAUTOS. So, when I see calling of some macro in the code I can't easily determine what folder the macro is stored in. Is there some function for this purpose or system table with names and physical paths to macroes which can be used in current SAS session?
Are you asking how to analyze the code and when you see a macro call figure out which file has the source code for that macro?
If you know the SASAUTOS settings then just loop over the folders in that list and look for the file that the right name.
So for example this program will read a list of macro names from input stream and generate a dataset with the the location.
This one should find the source files for SAS autocall macros LEFT and VERIFY.
data search ;
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 ;
autos=getoption('sasautos');
do i=1 by 1 until (path= ' ');
path=scan(autos,i,'( )');
if length(path) <= 8 then do;
if 0=fileref(path) then path=pathname(path) ;
end;
dlist=catx(' ',dlist,path);
end;
end;
input macro ;
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);
dname=dequote(scan(dlist,i,'( )'));
if dname=' ' then done=1;
else if fileexist(catx('/',dname,file)) then found=1;
end;
if ^found then dname=' ';
cards;
left
verify
;
proc print; run;
Note this will not work if you have defined more than one macro in each source file. That is something that you should not do with an autocall library, but even SAS sometimes does to make distribution easier. If you have that situation then might need to use a search tool like GREP to search the source for the %MACRO statements.
Use option mlogic and then check the logs. Log would tell you the path from where this macro being called.
In theory, what you are asking for is not 100% possible. It is conceivable that multiple folders contain a definition for the same macro (possibly the same definition, possibly a different definition). The one that gets used would depend on which macros have already been defined within the session (whether hard-coded, or by %include, or by invoking the macro with SASAUTOS), as well as the order of the folders within the SASAUTOS option. Also note, it is possible for the SASAUTOS definition to change as the program proceeds.
For just a basic approach, it shouldn't be too difficult to automate:
Are you asking how to analyze the code and when you see a macro call figure out which file has the source code for that macro?
If you know the SASAUTOS settings then just loop over the folders in that list and look for the file that the right name.
So for example this program will read a list of macro names from input stream and generate a dataset with the the location.
This one should find the source files for SAS autocall macros LEFT and VERIFY.
data search ;
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 ;
autos=getoption('sasautos');
do i=1 by 1 until (path= ' ');
path=scan(autos,i,'( )');
if length(path) <= 8 then do;
if 0=fileref(path) then path=pathname(path) ;
end;
dlist=catx(' ',dlist,path);
end;
end;
input macro ;
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);
dname=dequote(scan(dlist,i,'( )'));
if dname=' ' then done=1;
else if fileexist(catx('/',dname,file)) then found=1;
end;
if ^found then dname=' ';
cards;
left
verify
;
proc print; run;
Note this will not work if you have defined more than one macro in each source file. That is something that you should not do with an autocall library, but even SAS sometimes does to make distribution easier. If you have that situation then might need to use a search tool like GREP to search the source for the %MACRO statements.
Check dictionary table.
proc sql;
select *
from dictionary.macros ;
quit;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.