DATA Step, Macro, Functions and more

Macro reuse and macro calling

Reply
Occasional Contributor
Posts: 5

Macro reuse and macro calling

Dear all,

I have developed five macros, AA, BB, CC , DD and EE and compiled them in a user library.

To finish a task, CC would be called three times. The short calling sas program is like:

%AA

%BB

%CC

%CC

%CC

%DD

%EE

Each time the calling program stops after the first %CC is executed, the program will give error message like:

ERROR: Windows Error Reporting failed because the client was not found.

ERROR: Reac Access Violation In Task [Submit]

Exception Occurred at (6780EB72)

Task Traceback

Address Frame (DBGHELP API Version 4.0 rev 5)

bla

Even I slashed out all the three %CC, the program stops after %BB is executed and the error message shows up again, the later part won't be executed. But when I hit run again, the program will run all the way till the end, no error message at all!

In the code of AA.sas, BB.sas,  DD.sas,   there are small macros inside the macro definition of AA, BB, DD. But for CC.sas, EE.sas, there are small macros both inside and outside of macro definiton DD and EE. Since mstore was used for every macro definition, all the main and small macros were successfully compiled in the user library.

It's annoying to see the huge amount of red error message and to run and then stop at some point, hit run again and then verything is fine!!!

A SAS session only search the user library once and can only get 2-3 macros? Why it's ok when hit run gain? How to make them re-searching the user library?

Can anybody help, tons of thanks in advance!

Super User
Super User
Posts: 6,502

Macro reuse and macro calling

Is it possible that you have some nesting of the macro definition?  Perhaps %CC is trying to redefine a macro that is already running.

I would recommend separating your source code so that each macro is stored in a single file.  Each file shoud have only one macro definition in it and the first line should be the %MACRO statement and the last line the %MEND statement.  This will make it impossible to store all the files in one directory and have two different definitions for the same macro.

Save the program that calls these macros and run it non-interactively and see if you get the error messages.

Personally I normally just use autocall libraries rather than storing compiler macro definitions.  Then I only need to manage the source code files do not need to manage the compiler macro catalogs also.

Super User
Posts: 9,691

Macro reuse and macro calling

Defaultly,A SAS session only search the user library once.

But  there is an option to force SAS search many times.

You should check it in documentation. Sorry. I have forgotten.

Ksharp

Valued Guide
Posts: 2,175

Macro reuse and macro calling

mrecall         

Occasional Contributor
Posts: 5

Macro reuse and macro calling

Tom, Ksharp and Peter,

Thank you all for your kind help!

It seems mrecall searches autocall library for an undefined macro name, the .sas program of the macro definition is stroed in the library and then use:

options mautosource sasautos='G:\mymac\'

to reuse the macro.

But how about already compiled macro defintions? Is there any option to force a sas session search multiple times of the compiled macro catalog? The client was not found error message is because the sas session stopped or failed to search the macro name in the compiled catalog. I tried the above code for the compiled macro call, still does not work. I still need hit run, stop and hit run again to run all the macro calls.

If I use %include 'path\AA.sas';

           %include 'path\BB.sas';

           ....

           %include 'path\EE.sas';

Then no such problem. But apparently that's not a professional way to use and put open sas code on company public space.

I'm really frustrated with this situation.

Any further help deeply appreciated!

Valued Guide
Posts: 2,175

Macro reuse and macro calling

don't think we can help much more until you reveal those macros AA, BB and CC

Super User
Super User
Posts: 6,502

Macro reuse and macro calling

You will probably need to provide more details as to where exactly in the program it is getting the error.

A couple of things to try.

1) Make sure that the catalog with the compiled macros is READONLY.  You can do this with the operating system but you can also use the access=readonly option on the libname that you are using to point to the folder with the catalog.

2) Make sure that the programs are not trying to change the options that specify which macro catalog to use.

Super User
Posts: 9,691

Re: Macro reuse and macro calling

I am curious that You can't use compiled macro.

Once you stored compiled macro ,then you can use it as other SAS automatic macro like %ds2csv.

Did you try to use mstore to store this compiled macro firstly? and use sasautos and other option to search this compiled macro?

You can reference it in Macro documentation which illustrate how to store and reuse complied macro.

Ksharp

Occasional Contributor
Posts: 5

Re: Macro reuse and macro calling

Ksharp:

I'm so appreciate to your help!

The

auto call library and

compiled stored macro facility

are two different things. SAS's search order is:

1. macros defined in the current session

2. auto call library

3. compiled stored macro facility.

The auto call library is the kind that we define sas source code and then store the source code somewhere, the macro name should match the .sas program name. The MAUTOSOURCE, SASAUTOS, MRECALL options are associated with this situation.

But for compiled stored macro facility, the associated options are MSTORED, SASMTORE:

When compile I used:

options mstroed sasmstore=mymac;

libname mymam 'G:\myproj\';

%macro AA(            ) / store;

%mend;

When call the macro in other SAS session I used:

options mstroed sasmstore=mymac;

libname mymac 'G:\myproj\';

%AA;

I also tried to put those three options for autocall there, still doesn't work

It seems there is no much talk about how to force SAS search compiled stored macro facility many times, even no much talk about compiled stroed macro facitlity. I really hope I can get help from gurus here.

Super User
Super User
Posts: 6,502

Re: Macro reuse and macro calling

Try changing the LIBNAME statement that you use when using the macros to include the ACCESS=READONLY message.

Then if for some reason one of the macros was attempting to redefine a compiled macro it should complain about access and you might be able to trace the cause of your current error message.

libname mymac 'g:\myproj\' access=readonly;

Occasional Contributor
Posts: 5

Re: Macro reuse and macro calling

Tom,

I tried with your code there, still doesn't work.

Thanks a lot! In any case you get or run into the answer, please share with us.

Super User
Posts: 9,691

Macro reuse and macro calling

I tested it. You should close the first SAS session which create compiled maro .then use this compiled maro again.

When I open a SAS session and input:

%macro myfile /store;

proc print data=sashelp.class;

run;

%mend myfile;

libname xx v9 'c:\';

options mstored sasmstore=xx;

Then close this SAS session and open another SAS session input:

libname xx v9 'c:\';

options mstored sasmstore=xx;

%myfile

It worked.

Ksharp

Valued Guide
Posts: 2,175

Macro reuse and macro calling

why use compiled macros?

Occasional Contributor
Posts: 5

Macro reuse and macro calling

Ksharp,

Every time when I call the macros in another session, the SASMACR catalog is permanently stored and the compiling program is closed/nerver open. I still got the problem there, maybe too many macros and there is no much thing about force sas to search the catalog repeatedly.

Peter, we should not use compiled macros? I saw lots of this practice in company, I would like to get your suggestions.

Thanks, all!

Valued Guide
Posts: 2,175

Macro reuse and macro calling

my suggestion

use Sas autocall

Lots of flexibility and control

can add without overriding all

Ask a Question
Discussion stats
  • 15 replies
  • 345 views
  • 0 likes
  • 4 in conversation