DATA Step, Macro, Functions and more

Session compiled macro catalog

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 16
Accepted Solution

Session compiled macro catalog

How can I see information about all session compiled macros?

Thanks!!


Accepted Solutions
Solution
‎09-11-2013 02:37 PM
Super User
Super User
Posts: 6,497

Re: Session compiled macro catalog

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

View solution in original post


All Replies
Valued Guide
Posts: 3,208

Re: Session compiled macro catalog

If you just want to know the names of the automatic compiled ones ... look in the catalog present in saswork

---->-- ja karman --<-----
Occasional Contributor
Posts: 16

Re: Session compiled macro catalog

Thanks. I am looking for user compiled macros.

Valued Guide
Posts: 3,208

Re: Session compiled macro catalog

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.

---->-- ja karman --<-----
Respected Advisor
Posts: 3,887

Re: Session compiled macro catalog

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.

Respected Advisor
Posts: 3,777

Re: Session compiled macro catalog

PROC CATALOG

Super User
Super User
Posts: 6,497

Re: Session compiled macro catalog

data macros;

  set sashelp.vcatalg;

  where libname='WORK' and memname='SASMACR'

    and memtype='CATALOG' and objtype='MACRO';

run;

Occasional Contributor
Posts: 16

Re: Session compiled macro catalog

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.

Solution
‎09-11-2013 02:37 PM
Super User
Super User
Posts: 6,497

Re: Session compiled macro catalog

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

Occasional Contributor
Posts: 16

Re: Session compiled macro catalog

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. */

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 1736 views
  • 0 likes
  • 5 in conversation