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?
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.
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.
Maybe your Code Submission option is different. This is mine on the ENDSAS program:
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.
My setting is the same. Not sure why it did not work.
Try customising your submission options like this:
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.
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!
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.