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

How do I terminate a SAS EG session via code?

 

I have two process flows. The first flow has a check file criteria on whether a file exists and if that file does not exist, the SAS EG session should end and the next process flow should not run.

The code to check if the file exists is done but I can't seem to exit the EG session when the file is not found. I tried using endsas, abort exit but the second process flow still runs.

 

How do I go about that?

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Try customising your submission options like this:

SASKiwi_0-1670525781795.png

 

View solution in original post

9 REPLIES 9
ChrisHemedinger
Community Manager

Hi @antenga,

 

ENDSAS and ABORT EXIT will terminate the SAS session that EG connects to, but these won't close the EG application itself. There is no method in the EG user interface to say "if this happens, then close EG".

 

However, EG does have a scripting interface. This is covered in this article with some simple script examples:

Doing More with SAS Enterprise Guide Automation

 

The scripting interface requires a bit of code in VB Script or PowerShell or similar, and it's a way of running EG like a batch process and not an interactive user interface. Take a look at the examples and see if they help. If you need more help coming up with a script for your case, let me know.

SAS Hackathon registration is open! Build your skills. Make connections. Enjoy creative freedom. Maybe change the world.
SASKiwi
PROC Star

I created a process flow with two connected program tasks, the first of which just contained - ENDSAS; When I ran it the first one errored as it closed the SAS server session and the second one was cancelled. EG remained open. As @ChrisHemedinger says there is no way to programmatically close EG, but you can close the SAS server session within EG.

antenga
Obsidian | Level 7
Hi,
I did use the ENDSAS and on the log it says 'Error: The connection to the server has been lost' but it still runs the next flow.
Rgds.
SASKiwi
PROC Star

Maybe your Code Submission option is different. This is mine on the ENDSAS program:

SASKiwi_0-1670467234331.png

 

ChrisHemedinger
Community Manager

If the goal is to skip the next flow only...not necessarily close EG...then use a Conditional Node at the start of your next flow branch. You can check for a condition like presence of a macro variable or an error code...whatever makes sense. If the condition isn't met then the flow will not run.

SAS Hackathon registration is open! Build your skills. Make connections. Enjoy creative freedom. Maybe change the world.
antenga
Obsidian | Level 7

My setting is the same. Not sure why it did not work.

SASKiwi
PROC Star

Try customising your submission options like this:

SASKiwi_0-1670525781795.png

 

antenga
Obsidian | Level 7
Hi SasKiwi,

I tried this setting and it works as when the program ends, the query after it on the same flow and the next flow stops.

Thank you.

Rgds.
AlanC
Barite | Level 11

Another means is to use RPA to handle it. There are loads of RPA tools on the market. I like UiPath but Power Automate (free) can handle it too. See if Chris' idea works for your needs but look at RPA in case it doesn't. I use RPA a lot now (outside of SAS) and it simulates a person at a keyboard.

https://github.com/savian-net

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 9 replies
  • 1551 views
  • 1 like
  • 4 in conversation