The following macro should address this problem and some similar ones:
%macro runMacroFromEnv
/des='Set the environment value RUNMACRO to run a macro';
%if %sysfunc( envlen( RUNMACRO ) ) > 0 %then %sysget( RUNMACRO );
%mend;
For example: if you have the following file:
%macro foo;
%put I just ran foo;
%mend;
%macro runMacroFromEnv
/des='Set the environment value RUNMACRO to run a macro';
%if %sysfunc( envlen( RUNMACRO ) ) > 0 %then %sysget( RUNMACRO );
%mend;
%runMacroFromEnv;
and invoke SAS with:
sas runMacro.sas -set RUNMACRO %foo
Then somewhere in your log, you will see:
I just ran foo
A couple of important details:
- Using
-set works (at least) in Unix and Windows
- There are other mechanisms for setting environment variables, depending on your shell
- Don't forget the
% in -set RUNMACRO %foo
- See The set system option for more details