BookmarkSubscribeRSS Feed
KrisNori
Obsidian | Level 7

Hi,

 

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:

#!/bin/bash

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 ?

 

3 REPLIES 3
Tom
Super User Tom
Super User

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;
%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');
%A;

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

LinusH
Tourmaline | Level 20
"I'm getting errors". Any idea how we could help without seeing the errors, or your SAS program...?
Data never sleeps
Kurt_Bremser
Super User

@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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2330 views
  • 1 like
  • 4 in conversation