BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
_Dan_
Quartz | Level 8

Hello all,

 

I'm centralising recurring macro variables and functions into a .sas file which can be called via an %include statement.

 

To set the scene, I have a DI Studio job which first runs pre-code and then runs user-written code. The pre-code is a simple %include statement that "sets up" the job specifics. 

 

Centralising the recurring macro variables meant taking those variables out of the pre-code .sas file. Those same variables are now created inside of the centralised file, which is now referenced as another %include statement. That %include statement is nested - I am not calling two .sas files in the pre-code box in DI Studio, I am calling one .sas file, and that .sas file %includes the 'centralised' file.

 

The job now fails because a variable is no longer found. However, if I do %include the separate .sas files in the pre-code box in DI Studio, the job no longer fails.

 

What's happening:

DI Studio starts the job and calls the %include line in pre-code.

That .sas file runs. The first thing it does is run another %include line, and then attempts to go about doing what it always used to do.

It fails because, apparently, the macro variables created in the nested %include were never created.

 

But:

DI Studio runs the job and calls both .sas files in separate %include statements.

Each file has run separately.

Job runs fine.

 

 

Why is that?

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Look if there are macro definitions and calls involved that could cause variables to be put into a local symbole table.

Use %put statements that tell you exactly when a certain piece of code is entered and executed.

Use options source2; to have all code in the log.

 

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

Look if there are macro definitions and calls involved that could cause variables to be put into a local symbole table.

Use %put statements that tell you exactly when a certain piece of code is entered and executed.

Use options source2; to have all code in the log.

 

_Dan_
Quartz | Level 8
Hi Kurt, thanks for your reply.

I have %global statements in the 'centralised' file in an attempt to ensure the variables carry across.

Again, this works when the %include files are called in series within the pre-code box, but not when the %include line is run from within the other %include line...

I will try your suggestions as well.
_Dan_
Quartz | Level 8
It turns out this was absolute human error in that the file being referenced was not the file I was looking at in EGuide. I have accepted your reply @Kurt_Bremser as your reponse will help anyone else having a legitimate issue with %local variables.

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
  • 4 replies
  • 1258 views
  • 0 likes
  • 2 in conversation