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.
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
You could use the SASHELP.VCATALG SAS Data View:
data macros ;
set sashelp.vcatalg ;
where objtype="MACRO" ;
run ;
@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.
@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;
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
Thanks it worked.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: