BookmarkSubscribeRSS Feed
Laura1890
Calcite | Level 5

Hello,

we have written a piece of code in a programm that we would like to include in serveral processflows in our egp. We couldn't figure out how to do that and still be able to refine the code so that it is up to date everywhere it is included in the project.

Thanks for ypur help!

12 REPLIES 12
yabwon
Onyx | Level 15

I guess EG works on Windows and connects to a server, in such case store file with the code on the machne, e.g. "/myCodes/code.sas" and in your EG project add code block with this line:

%include "/myCodes/code.sas";

Bart

_______________
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



fja
Lapis Lazuli | Level 10 fja
Lapis Lazuli | Level 10

Hello!

... and Welcome to the community! 🙂 What about keeping it as a separate (external) piece of code and include it in the individual processes?

--FJa

Laura1890
Calcite | Level 5

This is what we tried: we saved the code snipped as "programm.sas"-file but we can include it once in the process flow (so that the filepath is correct and the programm ist not "embedded" in the project). If we add it a second time the programm is only embedded and thus can not be changed properly.

AhmedAl_Attar
Ammonite | Level 13

Hi @Laura1890 

How about taking @yabwon approach?

In every Process Flow, Add an embedded Program entry named "Call_External" (as an example) and have the following statement inside every embedded program

%include "<SavedExternalProgramm.sas>"; 

 

Just a thought, hope this helps

AhmedAl_Attar
Ammonite | Level 13

Hi @Laura1890 

Depending on how/where your EG execute the code. While EG can be installed on your personal Windows machine, it can execute code in the following modes

  1. Connecting to Local installation of SAS --> The code is executed from locally accessible location
  2. Connecting to Remote Server installation of SAS  --> The code has be stored on the Remote SAS server in order to be accessible and executed 

In order to include the program multiple times in EG, Check the Tools --> Options --> SAS Programs
There are "Additional SAS code" options  that might give what you are looking for

 

Hope this helps

fja
Lapis Lazuli | Level 10 fja
Lapis Lazuli | Level 10

Laura, 

could I ask another piece of information, please? The piece of code, what does it take as input and what does it produce as output? I had a little play with EG and was asking myself, what kind of program could sensibly used several times in a flow. Perhaps its input data is altered during the flow.

--fja

Laura1890
Calcite | Level 5

It only takes tables from the database as input and creates tables on our database as output.

Laura1890
Calcite | Level 5

I would like to share what we tried and worked so far:

You can include a new program to a process flow, save it and then change the filepath to the existing program (that is already included in another project flow in the same project). In order that the filepath still works with relative paths it is necessary to save the .egp-file using "save as"... and save as a new file. This sounds weird to me, but worked so far.

fja
Lapis Lazuli | Level 10 fja
Lapis Lazuli | Level 10

So it is to be included in the same Project but in different flows ... but per flow only once?

--fja

Laura1890
Calcite | Level 5

Yes, maybe this helps with the project setup: 

Laura1890_0-1681472335940.png

The programs 2/3/4/5 in Flow 2 and Flow 5 refer all to the (respectively) same .sas-file

yabwon
Onyx | Level 15

Does this code you want to attach execute the same thing in each of your programs? 

 

If so I would do the following: 

1) create file "myScript.sas" and inside it do:

%macro wrapperForMyScript();

/* Put your code here so it will be wrapped inside a macro */

%mend wrapperForMyScript; 

2) add an autoexec process calling %include (remember code is in macro now so it will compile)

yabwon_0-1681473292292.png

3) add %wrapperForMyScript() inside your programs in places you want your code to be executed.

 

Bart

 

 

_______________
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



fja
Lapis Lazuli | Level 10 fja
Lapis Lazuli | Level 10

@Laura1890 wrote:

You can include a new program to a process flow, save it and then change the filepath to the existing program (that is already included in another project flow in the same project). 


I could not reproduce that on EG 8.2. It complained, that the file was already referenced by the project ... 

So EG does obviously try to prevent you from including a program mutliple times in a project. One could possibly  trick EG by using OS links but then I would rather go for the %include method already mentioned in the first post by @yabwon.

--fja

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 12 replies
  • 1770 views
  • 2 likes
  • 4 in conversation