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

Hi,

 

I am using the SASAUTOS option to recall macros, without having to use the %INCLUDE statements and this working perfectly, but when I decide to change the SASAUTOS option mid-session it does not change.

 

Now, this causes an issue because imagine there were two macro locations, call them M_LIB1 and M_LIB2, which both contain the macro MYMACRO. When I open SAS and define the SASAUTOS to look at the MYMACRO in M_LIB1, it works as expected. Then I decide to change the SASAUTOS location to M_LIB2, during my current session, (i.e., I do not close SAS), the SASAUTOS does not seem to change and when I call MYMACRO expecting to be recalled from M_LIB2, it is actually being recalled from M_LIB1.

 

Below is some basic an example code, where I define the SASAUTOS location, call the macro then print the SASAUTOS locations to the log, then change the SASAUTOS location and repeat:


options mrecall mautosource 
        set = sasautos("!sasroot\core\sasmacro"
                       "C:\m_lib1");
%mymacro;
filename sasautos list;

                       
options mrecall mautosource 
        set = sasautos("!sasroot\core\sasmacro"
                       "C:\m_lib2");
%mymacro;
filename sasautos list;

The issue is that the FILENAME code with the LIST option displays the same results for both which implies SASAUTOS is not changing, I was expecting the second statement to show the M_LIB2 path but it shows the M_LIB1 path. Can anyone help?

1 ACCEPTED SOLUTION

Accepted Solutions
craig159753
Quartz | Level 8

Hi Paige and Tom,

 

Thank you for your help, using the SYSMACDELETE it works, so I made a rough macro to delete specifically the work macros, as I do not need any of them if I am changing the SASAUTOS option.

 


%* Reset / Remove any work macro(s);
%macro m_reset();

  %local m_work_macros m_work_macro;
  %let m_work_macros=;
  %let m_work_macro=;

  %* Fetch work macro(s) previously compiled;
  proc sql noprint;
    select distinct strip(objname) 
into :m_work_macros separated by " " from sashelp.vcatalg where upcase(objtype)="MACRO" and upcase(libname)="WORK" and compress(upcase(objname)) ne "M_RESET"; quit; %* Loop through work macro(s) previously compiled and remove them; %if %length(&m_work_macros.) > 0 %then %do; %do i = 1 %to %sysfunc(countw(&m_work_macros.)) %by 1; %* Define macro; %let m_work_macro = %scan(&m_work_macros., &i.); %* Ignore current macro / null terms; %if %upcase(&m_work_macro.) ne M_RESET and %length(&m_work_macro.)>0 %then %do; %put NO%STR(TE:) Following work macro removed - %upcase(&m_work_macro.); %sysmacdelete &m_work_macro. / nowarn; %end; %end; %end; %mend m_reset; %m_reset;

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

Works for me if you remove set = from the options statement. And then use

 

%put %sysfunc(getoption(sasautos));

instead of the filename command.

 

Your options statement changes the value of the option sasautos, it is not changing the the meaning of the fileref sasautos

--
Paige Miller
craig159753
Quartz | Level 8

Hi Paige,

 

So you are suggesting the following:

 

options mrecall mautosource 
        sasautos=("!sasroot\core\sasmacro"
                       "C:\M_LIB1");
%put %sysfunc(getoption(sasautos));
%mymacro;
                       
options mrecall mautosource 
        sasautos=("!sasroot\core\sasmacro"
                       "C:\M_LIB2");
%put %sysfunc(getoption(sasautos));
%mymacro;

Which yes does show two different SASAUTOS options, however the macro called is from M_LIB1 exclusively, it seems the second location does not take priority even when SASAUTOS is redefined.

I have also tried the following


%sysmstoreclear;
proc catalog catalog = work.sasmacr kill force;
quit;

Which would clear the work areas, and still no luck

Tom
Super User Tom
Super User

Sounds like you are asking how to remove the already compiled macros so that the next call that same macro name will find the macro definition using the new search path.

 

SAS has provided a macro command for deleting a compiled macro.

 

Here is a user defined macro that makes using it easier:

https://github.com/sasutils/macros/blob/master/macdelete.sas

 

PaigeMiller
Diamond | Level 26

Once you call %mymacro, it remains known to SAS for that entire SAS session (that is, until you close SAS). So changing the SASAUTOS option doesn't affect %mymacro, the SAS system still knows about it.

 

You can use

%sysmacdelete mymacro/nowarn;
--
Paige Miller
craig159753
Quartz | Level 8

Hi Paige and Tom,

 

Thank you for your help, using the SYSMACDELETE it works, so I made a rough macro to delete specifically the work macros, as I do not need any of them if I am changing the SASAUTOS option.

 


%* Reset / Remove any work macro(s);
%macro m_reset();

  %local m_work_macros m_work_macro;
  %let m_work_macros=;
  %let m_work_macro=;

  %* Fetch work macro(s) previously compiled;
  proc sql noprint;
    select distinct strip(objname) 
into :m_work_macros separated by " " from sashelp.vcatalg where upcase(objtype)="MACRO" and upcase(libname)="WORK" and compress(upcase(objname)) ne "M_RESET"; quit; %* Loop through work macro(s) previously compiled and remove them; %if %length(&m_work_macros.) > 0 %then %do; %do i = 1 %to %sysfunc(countw(&m_work_macros.)) %by 1; %* Define macro; %let m_work_macro = %scan(&m_work_macros., &i.); %* Ignore current macro / null terms; %if %upcase(&m_work_macro.) ne M_RESET and %length(&m_work_macro.)>0 %then %do; %put NO%STR(TE:) Following work macro removed - %upcase(&m_work_macro.); %sysmacdelete &m_work_macro. / nowarn; %end; %end; %end; %mend m_reset; %m_reset;
Quentin
Super User

I think the key point is that MRECALL does not do what you hoped it would do.

 

I think you hoped that MRECALL would mean "every time I call a macro, look in the autocall libraries to see if there is a .sas file for the macro and re-compile it."

 

Instead, MRECALL means "when I call a macro that has is not currently compiled, even if earlier in the session I looked in the autocall libraries for it, look again."

 

For development purposes, it might be nice to have a SUPERMRECALL that would do what you want.  Without that, as others have mentioned, to get an autocall macro to re-compile, your options are either to delete definition from the compiled macro catalog, or to %include the macro code.

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 6 replies
  • 1846 views
  • 0 likes
  • 4 in conversation