BookmarkSubscribeRSS Feed
Martin_Bryant
Quartz | Level 8

Hi,

 

I have a large SAS EG project containing programs and reports that needs to be run multiple times, each time with a different parameter value. Currently it is a project with a date prompt. I need to run this multiple times (and regularly) with different dates. Sticking everything into a macro would be a lot of work and messy. Is there a way to either...

 

  • Call a project with the prompt value in a script?
  • Call put all of the programs and reports in a single program? (Then I can use a macro around a %include)
  • Anything else that will solve this tidily?

I will probably have to apply the solution to multiple projects so I'd like to do it right first time.

 

Happy to answer questions. Thanks.

16 REPLIES 16
SASKiwi
PROC Star

How many times do you want to call your project and what are the dates you want to use?  Is there a rule for the dates like run for every date in the last 7 days for example? If there is a rule involved, you can code for it. If not you could record the dates in an input file and get your project to loop through them.

Martin_Bryant
Quartz | Level 8

Well, I'm hoping that the call to run this multiple times can still be within SAS EG code and therefore I can use prompts to guide this. At worst I can have a SAS EG project to write the values to a data table that the main code can read and use to control the loop.

 

My question all hangs on the mechanics of how to code the loop. I am am pretty sure that I can do it with a macro but it wouldn't be a very tidy solution. I just don't think that macros are a very tidy solution to anything though. In fact I am really not very impressed with the majority of the SAS language.

 

Is it possible to get one SAS EG project to call another?

Kurt_Bremser
Super User

If things have not changed recently, EG projects do not have the concept of loops. It is also not possible (IIRC) to connect a node in a process flow back to an earlier node in the flow, allowing you to create a "manual" loop.

 

IMO you need to convert your project to code, around which you can then wrap any of the looping methods provided by SAS (%DO in macro language, or using CALL EXECUTE with data read from a dataset).

Martin_Bryant
Quartz | Level 8

Thanks. I had a nasty feeling that would be the case.

 

OK. I'll start making a macro... 😞

 

Martin

yabwon
Onyx | Level 15

If you are planning to extract code form EG project maybe this make your life easier: 

https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-list-all-programs-included-in-an-egp-fi...

 

Bart

 

P.S. if you planing to share "a lot of code" with other users to run it, how about considering SAS Packages: 

https://github.com/yabwon/SAS_PACKAGES

Intro video plus some examples (~60 mins): https://youtu.be/T52Omisi0dk&t=0s

 

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Martin_Bryant
Quartz | Level 8

Many thanks. All of our files are stored on the server and we only get relative names, so I'm not sure that this will work for us, but it looks very useful if I can work out how to access our paths. Many thanks. We aren't allowed to store files externally to the server. Sigh.

Patrick
Opal | Level 21

@Martin_Bryant wrote:

Many thanks. All of our files are stored on the server and we only get relative names, so I'm not sure that this will work for us, but it looks very useful if I can work out how to access our paths. Many thanks. We aren't allowed to store files externally to the server. Sigh.


What do you mean by relative names? Relative paths beginning from what's defined for EG folder "Files? If so right click onto one of the programs in EG and select "Copy path" and then paste it into a program node. That should give you the absolute path <path to Files>/<relative path>

 

With SAS 9.4 DI Studio got a loop transformation that also allows for parallel execution of the loops. 

With Viya SAS Studio Flow there isn't a loop step yet but it shouldn't be hard to create a custom step for this (2 steps actually, loop start and loop end). There is a migration path for SAS EG flows to SAS Studio Flow.

 

Martin_Bryant
Quartz | Level 8

We are on SAS EG 7.12.

 

Yes, paths from the server. Thanks, I am familiar with the location as per the program properties, I just haven't used this path when referencing code.

AlanC
Barite | Level 11

Consider creating a SAS Custom Task. I haven't done this in a while so bear with me.

 

SAS EG is written in C#. You can make a custom task that takes parameters (custom UI) and loops the tasks. I have built these for SAS clients before who were in a similar position. There is a C# interface you have to implement and then code up whatever you want. You are limited to the Framework but that is more than enough power.

 

See this page and book on how to do it or refer to examples online. I have C#/SAS examples on my github site as well. There is also a program there that extracts out the SAS code from EG. However, I think a custom task works better (or is at least worth looking into).

https://github.com/savian-net
Martin_Bryant
Quartz | Level 8

Custom tasks look interesting. Not used them before. The problem here is that I suspect our SysAdmin won't let me write C++ code and the last time I wrote C++ was probably 30 years ago. Never really mastered OO languages. I'm a Functional Language man. 🙂

AlanC
Barite | Level 11

C#, not C++.

 

Custom tasks live on your side of the equation. You load them via the EG menu.

 

Chris' examples make it easy to customize. You can copy his code and modify as needed. You have to comply with the contract (i.e. interface). Ex. Martin  object implements IHuman and IMammal and therefore has certain properties and actions. 

 

Your call but a way to fix the issue. Just wanted you to be aware of it. You could do a follow along on a simple task and see what you think. 

https://github.com/savian-net
Martin_Bryant
Quartz | Level 8

Ah, my mistake. Never done C#.

 

I will certainly take a look at this. Thanks again.

Sajid01
Meteorite | Level 14

Hello @Martin_Bryant 
In addition to the many suggestions above, I  suggest  the following:

1.The program needs to be run multiple times and not sure how many times to run,

 Convert your program to a stored process with prompts as needed. 
The stored process can be be run as and when needed  and the parameter input.

In addition the stored process can be invoked as using http request (post or get as needed) / REST API.

2.The program has to be run at predetermined intervals
 Use a scheduler for example to run the job. The parameter value can be stored in a text file and the job reads it.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 16 replies
  • 1254 views
  • 3 likes
  • 8 in conversation