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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

8 REPLIES 8
Reeza
Super User

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.

elwayfan446
Barite | Level 11

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.

Reeza
Super User

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

elwayfan446
Barite | Level 11

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.

Reeza
Super User

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

elwayfan446
Barite | Level 11

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.

Reeza
Super User

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. 

 

 

elwayfan446
Barite | Level 11

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 8 replies
  • 2309 views
  • 1 like
  • 2 in conversation