I have 2 jobs in DI studio. In job 1, I need to define some variables that I need to use in job2.
So in job 1, I do:
proc sql ;
select col1 into :new_col from table1 where 1 = 1;
quit;
%global new_col;
In job 2:
I try to use the macro variable new_col, but the variable name cannot be resolved.
How to solve this?
Do you mean job or step?
Macro variables last only for the duration of the job, so you must save the value in a table or in a flat file for the next job to access it.
If you mean step:
1- The global statement must come before the value assignment.
2- Unless your proc sql runs inside a macro, new_col will always be global
3- Fyi, if the select statement reads no records, no value is assigned
Do you mean job or step?
Macro variables last only for the duration of the job, so you must save the value in a table or in a flat file for the next job to access it.
If you mean step:
1- The global statement must come before the value assignment.
2- Unless your proc sql runs inside a macro, new_col will always be global
3- Fyi, if the select statement reads no records, no value is assigned
Not sure if passing macro variable values between jobs is the best solution, but I don't know the full picture, so...
If those two jobs are always running in sequence you could put them together in the same job (job in job). Then the jobs will execute in the same SAS session.
Another option is to have a routine that stores the macro variable values in a permanent stored table, and then a a routine that creates macro variables in the new session based on that table. Using SASHELP.VMACRO could be an option...
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.