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

How can I see information about all session compiled macros?

Thanks!!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

9 REPLIES 9
jakarman
Barite | Level 11

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

---->-- ja karman --<-----
Jakkas
Calcite | Level 5

Thanks. I am looking for user compiled macros.

jakarman
Barite | Level 11

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 --<-----
Patrick
Opal | Level 21

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.

data_null__
Jade | Level 19

PROC CATALOG

Tom
Super User Tom
Super User

data macros;

  set sashelp.vcatalg;

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

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

run;

Jakkas
Calcite | Level 5

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.

Tom
Super User Tom
Super User

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

Jakkas
Calcite | Level 5

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-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
  • 9 replies
  • 4266 views
  • 2 likes
  • 5 in conversation