Amadeus cookies policy - you'll see this message only once.

Amadeus use cookies on this website. They help us to know a little bit about you and how you use our website, which improves the browsing experience and marketing - both for you and for others. They are stored locally on your computer or mobile device. To accept cookies, continue browsing as normal. Or, go to the privacy policy for more information.

How to Keep Secret Code Secret

Storing a compiled macro

Often when using the macro language we tend to compile a macro and then run it in the same SAS session. The source code for the macro can be either in the current SAS program or within an autocall library but in both cases the macro is both compiled and executed when used.

It is however possible to permanently store the macro in its compiled form, and then execute it directly at a later stage. This allows the macro to be executed by users without them having the ability to alter or directly view the source code.

This is enabled by setting the MSTORED option and specifying a library in which to store the compiled macro with the SASMSTORE= option.

libname mac_lib 'C:Temp';

options MSTORED SASMSTORE=mac_lib;

Once these options are set then simply adding the STORE option to the macro definition will cause the compiled form to be stored in the specified location.

%macro compmac(parameter) / STORE ;
  data test;
    var="&parameter ";
proc print data=test; run; %mend;

The pre-compiled macro can now be executed directly as long as the MSTORED and SASMSTORE= options have been set.

Hiding the source code from the user.

Although the user is now unable to view the source code for the macro directly, this can be achieved by setting the macro debugging option MPRINT. Now all the SAS code generated by the macro will be displayed in the log.

options MPRINT;

Produces the following log allowing the generated code to be viewed.

18   options MPRINT;
19   %compmac(Amadeus);
MPRINT(COMPMAC):   data test;
MPRINT(COMPMAC):   var="Amadeus ";
NOTE: The data set WORK.TEST has 1 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.03 seconds cpu time 0.00 seconds
MPRINT(COMPMAC): proc print data=test; MPRINT(COMPMAC): run;

This can be prevented by adding the SECURE option to the macro definition.

%macro compmac(parameter) / STORE SECURE;
  data test;
    var="&parameter ";
proc print data=test; run; %mend;

Now the log will not display the generated code even if the MPRINT option has been set.