How can I see information about all session compiled macros?
Thanks!!
Depends on what you mean by "session". When you run SAS directly from the operating system it uses WORK.SASMACR catalog. But a few years ago when playing with Enterprise Guide I found it was using WORK.SASMAC1 instead.
Try this little program to take a snapshot from the metadata before and after compiling a macro and see what changes.
proc sql ;
create table before as
select libname,memname,objname,created from dictionary.catalogs
where objtype='MACRO'
order by 1,2,3
;
%macro test2; %mend ;
create table after as
select libname,memname,objname,created from dictionary.catalogs
where objtype='MACRO'
order by 1,2,3
;
quit;
proc compare data=before compare=after listall ;
id libname memname objname;
run;
36360 - How to determine whether a macro exists within a SAS session
If you just want to know the names of the automatic compiled ones ... look in the catalog present in saswork
Thanks. I am looking for user compiled macros.
Please explain me the difference or your intention of your question.
Macros can be pre-compiled by users and by options getting used.
Autocall macros being used user/session are getting compiled and by that the compiled version gets stored in that catalog.
Manually compiling of macros is also possible by using the %inc statement or defining them in-stream in other code.
If not explicitly defined different then session specific macros get compiled into a catalog in WORK. I believe the catalog name is sasmacr. Use Proc Catalog to list it's content.
I believe there is also a sashelp table listing compiled macros.
PROC CATALOG
data macros;
set sashelp.vcatalg;
where libname='WORK' and memname='SASMACR'
and memtype='CATALOG' and objtype='MACRO';
run;
The following doesn't work. It gives an error saying wor.SASMACR doesn't exist. So I don't see a way to see the session compiled macros using PROC CATALOG.
Proc catalog cat=work.sasmacr;
contents out=temp;
run;
SASHELP.VCATALG Does show me all the session compiled macros. But I am not able to delete a macro from it. So how would you delete a session compiled macro from work.SASMACR? If I could get to the catalog from PROC Catalog I could use delete statement.
Depends on what you mean by "session". When you run SAS directly from the operating system it uses WORK.SASMACR catalog. But a few years ago when playing with Enterprise Guide I found it was using WORK.SASMAC1 instead.
Try this little program to take a snapshot from the metadata before and after compiling a macro and see what changes.
proc sql ;
create table before as
select libname,memname,objname,created from dictionary.catalogs
where objtype='MACRO'
order by 1,2,3
;
%macro test2; %mend ;
create table after as
select libname,memname,objname,created from dictionary.catalogs
where objtype='MACRO'
order by 1,2,3
;
quit;
proc compare data=before compare=after listall ;
id libname memname objname;
run;
36360 - How to determine whether a macro exists within a SAS session
Thanks Tom. So what I was missing was that it is called SASMAC1 instead of SASMACR. Here is how I am able to uncompile a macro.
%Macro MyMacro1;
%put &SYSMACRONAME. says Shazzam;
%Mend;
%myMacro1 /* Runs fine. */
Proc catalog cat=work.SASMAC1;
contents out=temp; /* Shows that myMacro1 is in the work macro catalog. */
Run;
Proc catalog cat=Work.SASMAC1;
delete MyMacro1 (ET=MACRO); /* Deletes myMacro1 from work macro catalog. */
Run;
%myMacro1 /* Error. the macro definition is no longer available. */
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.