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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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