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?
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.
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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.