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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

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

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

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

LinusH
Tourmaline | Level 20

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

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