Executing SAS macros from command line

Occasional Contributor
Posts: 17

Executing SAS macros from command line

[ Edited ]



I have a some macros, say, A to E, executed in that order (A calls B, C, D and E). Each macro is in a separate .SAS file(say, Macro A is in A.sas, B in B.sas and so on). The parameters passed to the macros and those used in the macros are stored in a SAS dataset (central table).


I am trying to write a UNIX shell script that compiles the macros at run time as Stored Compiled Macros (I included the /STORE syntax in macros) and executes them.


My shell script:


sas -AUTOEXEC "/sasdata/autoexec/project_autoexec.sas"  A.sas B.sas C.sas D.sas E.sas.


I also tried using separate lines for each .sas file.


sas -AUTOEXEC "/sasdata/autoexec/project_autoexec.sas"  A.sas

sas B.sas


sas E.sas


I am getting errors. Can some one help me ?


Super User
Super User
Posts: 6,498

Re: SAS Macros

[ Edited ]

Are the files macros or programs?   A macro doesn't really do anything until it is invoked.  It sounds like you are taking about a series of programs instead of macros.


If they really are macros then perhaps you want to look into using an AUTOCALL library.  Store each macro definition in its own file with the filename being the name of the macro plus an extenson of .sas (if you use Unix is important that the fllename be in all lowercase letters). Then point the SASAUTOS option to the directory where the macro code files are stored.  SAS will then read the flle and compile the macro the first time it is requested in your actual program.  So for example you could have a file named 'a.sas' that looked like:

%macro A;
%put Macro A will now call macro B;
%mend A;

And another file named 'b.sas' that looked like:

%macro B;
%put Macro B is running now;
%mend B;

You could then create a program that looked something like

%put Now running my program ;
options append=sasautos=('path to where macro source code lives');

Or since you seem to have an AUTOEXEC.SAS file you could put the SASAUTOS option setting into the autoexec file.

Super User
Posts: 5,255

Re: Executing SAS macros from command line

"I'm getting errors". Any idea how we could help without seeing the errors, or your SAS program...?
Data never sleeps
Super User
Posts: 6,928

Re: Executing SAS macros from command line

KrisNori wrote:



I am getting errors. Can some one help me ?


Yeah. And a bicycle was stolen in Beijing.

Which, as information goes, is about as relevant to your problem.


Please post the relevant parts of your log files, if you get any. Or the operating system's response when you executed your command lines.


If macro A.sas contains valid %include statements for the other macros, you only need to execute A.sas.

Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 3 replies
  • 1 like
  • 4 in conversation