DATA Step, Macro, Functions and more

SAS global macro variable not being resolved

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 82
Accepted Solution

SAS global macro variable not being resolved

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?


Accepted Solutions
Solution
‎08-05-2015 05:08 PM
PROC Star
Posts: 1,555

Re: SAS global macro variable not being resolved

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

View solution in original post


All Replies
Solution
‎08-05-2015 05:08 PM
PROC Star
Posts: 1,555

Re: SAS global macro variable not being resolved

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

Super User
Posts: 5,254

Re: SAS global macro variable not being resolved

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

Data never sleeps
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 206 views
  • 0 likes
  • 3 in conversation