BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASuserlot
Barite | Level 11

For our projects some macros are called into the session using a project setup macro from a specific folder, some times we use SASAUTOS options.  People who are in the project are not aware of what macros are available . Is there any way we can find out the list of macros available during the sessions.

 

Thank you for your advise in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Get this list of directories

data paths ;
  length autos dlist path $32767 ;
  autos=getoption('sasautos');
  do i=1 by 1 until (path= ' ');
    path=scan(autos,i,'( )','q');
    if length(path) <= 8 then do;
        if 0=fileref(path) then path=pathname(path) ;
    end;
    dlist=left(trim(dlist)||' '||path);
  end;
  length dirnum 8 directory $256 ;
  do dirnum=1 to countw(dlist,'( )','q');
    directory=dequote(scan(dlist,dirnum,'( )','q'));
    output;
  end;
  keep dirnum directory;
run;

Now scan the directories for files that look like they could be autocall macros.

data macros;
  length dirnum filenum 8 macro $32 filename $256 ;
  set paths;
  fileref='macdir';
  rc=filename(fileref,directory);
  did=dopen(fileref);
  do filenum=1 to dnum(did);
    filename=dread(did,filenum);
    if lowcase(scan(filename,-1,'.'))='sas' then do;
      macro = substrn(filename,1,length(filename)-4);
      if length(macro) <= 32 and nvalid(macro,'v7') and macro=lowcase(macro) then output;
    end;
  end;
  rc=dclose(did);
  rc=filename(fileref);
  keep dirnum filenum macro directory filename ;
run;

Here are the first few results on my PC

Tom_0-1658329127091.png

 

View solution in original post

5 REPLIES 5
AMSAS
SAS Super FREQ

You could use the SASHELP.VCATALG SAS Data View:

data macros ;
	set sashelp.vcatalg ;
	where objtype="MACRO" ;
run ;
Tom
Super User Tom
Super User

@AMSAS wrote:

You could use the SASHELP.VCATALG SAS Data View:

data macros ;
	set sashelp.vcatalg ;
	where objtype="MACRO" ;
run ;

That would only find macros that have already been compiled.  It would not search the directories listed in the SASAUTOS option to find any available autocall macros that have not yet been called.

 

For that you might want to write a data step that loops over the directories and opens them and uses DREAD() to extract the filenames and find any that look like "macroname.sas".    You might get a start by looking at this macro https://github.com/sasutils/macros/blob/master/maclist.sas.  But that macro is trying to do the reverse which is locate the source code for the macros that have already been compiled.

SASuserlot
Barite | Level 11

@Tom  you are correct, It given only  that are already compiled , I could not see any  macros that suppose to see. I tried these two. Can please provide a sample code that you mentioned.

proc sql noprint;
   create table xx as select * 
    from dictionary.catalogs
    where objtype='MACRO'
   ;
quit;

proc sql noprint;
   create table yy as select * 
    from sashelp.vcatalg
    where objtype='MACRO'
   ;
quit;

SASuserlot_0-1658328056501.png

 

Tom
Super User Tom
Super User

Get this list of directories

data paths ;
  length autos dlist path $32767 ;
  autos=getoption('sasautos');
  do i=1 by 1 until (path= ' ');
    path=scan(autos,i,'( )','q');
    if length(path) <= 8 then do;
        if 0=fileref(path) then path=pathname(path) ;
    end;
    dlist=left(trim(dlist)||' '||path);
  end;
  length dirnum 8 directory $256 ;
  do dirnum=1 to countw(dlist,'( )','q');
    directory=dequote(scan(dlist,dirnum,'( )','q'));
    output;
  end;
  keep dirnum directory;
run;

Now scan the directories for files that look like they could be autocall macros.

data macros;
  length dirnum filenum 8 macro $32 filename $256 ;
  set paths;
  fileref='macdir';
  rc=filename(fileref,directory);
  did=dopen(fileref);
  do filenum=1 to dnum(did);
    filename=dread(did,filenum);
    if lowcase(scan(filename,-1,'.'))='sas' then do;
      macro = substrn(filename,1,length(filename)-4);
      if length(macro) <= 32 and nvalid(macro,'v7') and macro=lowcase(macro) then output;
    end;
  end;
  rc=dclose(did);
  rc=filename(fileref);
  keep dirnum filenum macro directory filename ;
run;

Here are the first few results on my PC

Tom_0-1658329127091.png

 

SASuserlot
Barite | Level 11

Thanks it worked. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1015 views
  • 3 likes
  • 3 in conversation