BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DmitryErshov
Obsidian | Level 7

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.

View solution in original post

5 REPLIES 5
RahulG
Barite | Level 11

Use option mlogic and then check the logs. Log would tell you the path from where this macro being called.

DmitryErshov
Obsidian | Level 7
Thanks for reply, RahulG.

But I don't want the macro to be executed. Is there some way to prevent macro execution?
Astounding
PROC Star

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:

 

  • Get a list of all folders defined within SASAUTOS
  • For each such folder, get a list of the files within
Tom
Super User Tom
Super User

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.

Ksharp
Super User

Check dictionary table.

 

proc sql;
select *
 from dictionary.macros ;
quit;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 6267 views
  • 4 likes
  • 5 in conversation