Desktop productivity for business analysts and programmers

Using a Macro to assign Output Datasets in EG

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 138
Accepted Solution

Using a Macro to assign Output Datasets in EG

Hi!

 

Yesterday I learned how to write a macro that would auto map librarys, specifically a dev and prod library for that example. 

 

https://communities.sas.com/t5/General-SAS-Programming/SAS-equivalent-to-SQL-variables/m-p/249329#M3...

 

What I am trying to figure out if I can do in EG is call a macro in the Output of a task I am creating so that it will assign the library in the macro.  All I seem to be able to do is manually point to a library when setting the ouput location.  My goal is to create process flows where I only have to change the macro for output sets without having to change each individual task.  I  would assign the library to the macro in the first program task of the process flow and then the tasks reference it from there.

 

Capture.PNG

 

Do you know of any way I could make this work?


Accepted Solutions
Solution
‎02-11-2016 11:54 AM
Grand Advisor
Posts: 17,313

Re: Using a Macro to assign Output Datasets in EG

You need to keep the library name the same, it doesn't have to point to the same location in each project. All that matters is that the library name is the same.

 

ie project1

 

libname my_lib 'C:\_localdata\project1';

 

Project 2

 

libname my_lib 'C:\_localdata\project2';

 

Given what you're saying, I'd do it the macro variable way I suggested at first though. So the macro variable is set at the beginning of the project and set it up properly in each query. 

 

 

View solution in original post


All Replies
Grand Advisor
Posts: 17,313

Re: Using a Macro to assign Output Datasets in EG

Does creating the library depend on the task output? I'm not understanding why the macro/macrocall isn't in a program or autoexec that you then call in another program and include that as a node in your process flow.

Frequent Contributor
Posts: 138

Re: Using a Macro to assign Output Datasets in EG

No, all of the tasks in a particular process flow would be the library I would set in my macro.  I would set it as a node as the first task in my flow and then ideally, each task would know that was the library the data set should output to.  As of now, I have to browse to the library in each task to indicate where I want the output data set to go.  I would like it to "know" based on the macro I set in the first node.

 

I hope that makes more sense.

Grand Advisor
Posts: 17,313

Re: Using a Macro to assign Output Datasets in EG

Create a macro variable that references the library and then use that in your queries.

 

%let lib_day=mylib;

 

Then in each of the queries, point to that library which will resolve to whatever you've set it to.

 

&lib_day..my_data

Frequent Contributor
Posts: 138

Re: Using a Macro to assign Output Datasets in EG

If I use a program to write the query that works fine.  Is there a way to do it using query builder like I am doing in my screenshot?  I have a lot of tasks that are not programs and I simply use query builder to get the data I need for the new data sets.

Grand Advisor
Posts: 17,313

Re: Using a Macro to assign Output Datasets in EG

So you want a library set up that defaults to where everything goes? But you don't want to type it out for each query. So these aren't process flows, its more of an everyday workflow issue?

 

Do you want ALL queries to go to this location? Because I think that would be the only way to default it the way you're asking.  

 

 

Under Tools>Options>Output Library

Click Add

Add your library name

Move it to the top

 

delete mylib code.JPG

 

my_lib setup.JPGdelete mylib.JPG

Frequent Contributor
Posts: 138

Re: Using a Macro to assign Output Datasets in EG

Not exactly but maybe I can explain a little better.

 

So, for example.

 

I have 3 projects, each having a primary process flow.  Each project's process flow has similar tasks, but the data sets need to be saved to different libraries depending on which project I am running.  So, depending on which project I was using, I would set the macro in the first node via a program (similar to your earlier example with the %let statement). Then, ideally, all tasks in that project would save data sets to the library assigned in that macro.

 

In the 2nd and 3rd project, they would have different libraries assigned for their data sets to be saved to.  If this worked, none of the actual tasks would ever have to be edited, just the macro for that specific project to point to its library.

 

From your latest example, I could set the default each time I opened a specific project, but I wouldn't be able to automate because EG would default to that library no matter which project I was using.

Solution
‎02-11-2016 11:54 AM
Grand Advisor
Posts: 17,313

Re: Using a Macro to assign Output Datasets in EG

You need to keep the library name the same, it doesn't have to point to the same location in each project. All that matters is that the library name is the same.

 

ie project1

 

libname my_lib 'C:\_localdata\project1';

 

Project 2

 

libname my_lib 'C:\_localdata\project2';

 

Given what you're saying, I'd do it the macro variable way I suggested at first though. So the macro variable is set at the beginning of the project and set it up properly in each query. 

 

 

Frequent Contributor
Posts: 138

Re: Using a Macro to assign Output Datasets in EG

Oh my... I can't believe that didn't dawn on me.  Thank you soooo much.  This is going to save a lot of manual work for me. Smiley Happy

☑ This topic is SOLVED.

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

Discussion stats
  • 8 replies
  • 602 views
  • 1 like
  • 2 in conversation