12-19-2012 09:43 AM
How do end SAS EG when a condition is met?
Here is my code:
if flag="Y" then endsas;
But it's not good!
Thanks in advance!
12-20-2012 05:09 AM
I think this depends on the state you want EG to be left in when you stop the process...
The 'proper' way of doing this I would guess would be to use STOP or ABORT in your data step. I have never managed to get this working as I would like but here is what I found,
If you use ABORT RETURN then the program will stop running however it will also stop your EG session meaning you will need to reconnect your connection profile before you can continue and you will lose any output that has already been run elsewhere in the project.
Looking at this page (http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000230210.htm) it looks like you can put options in to stop this but i have never got it working.
Alternatively, the way I handle this is by creating my own error handling. The code below has the extra macros I use at the start but I normally have these in an autoexec flow for my project so I can use them everywhere. For this to work you need to put &Cancel after every run statement and &SQLCancel in your proc SQL statements.
I tend to go overkill and put a %Reset_Errors at the start and end of every program but if you want a raised error to stop other programs from running too you could leave it out or have different levels of raised errors.
Hope it helps.
/* AutoExec code */
%global Cancel SQLCancel;
%put ERROR-My Error: &text;
/* Program */
length myVar 8;
if myVar=3 then do;
%if &MyVar=1 %then %Raise_Error(This is an error);
proc sql &sqlcancel;
select * from m02;
12-20-2012 09:09 AM
ERRORABEND and ENDSAS are generally not good to use within EG, as it ends the SAS Workspace session immediately and prevents EG from collecting any remaining results, including SAS log and ODS output. It's the equivalent of "hanging up the phone" before you've had a chance to hear the bad news from your SAS program.
The same holds true for other uses of SAS Workspaces, such as SAS stored processes. It's better to write your program to detect the bad conditions and then conditionally run program segments only when all good conditions are met.
You can use Conditions in your EG process flow to run a set of tasks or programs only when the condition is met. Conditions can be based on prompt values, macro variables, and data set values. See the SAS Enterprise Guide online help for more about setting Conditions.
Here's an old post with a brief description of Conditions:
12-20-2012 11:05 AM
Actually,I want to first determine whether DWH is avaiable or not ,if not,then
I have to stop the Program Jobs which produce results and transfer
files to other colleague,cause the Project need to be run automatically.That is,end SAS EG,and restart EG project when DWH are avaiable.
I am used to SAS programmer,and along with SAS EG four months.
Just learn from your Blog,tomorrow I'll check which version of My SAS
EG.I'm afraid that it is version 4.1 .
12-21-2012 08:52 AM
You also might want to look into SAS DIS. It is a product that is better designed for running software in a "production" type of environment, whereas I consider EG better for development, testing, and adhoc analyses, precisely because this type of issue comes up.
06-28-2016 08:57 AM
I'm running SAS 9.4 M3 from Enterprise Guide 7.1 HF1 (126.96.36.1992) (32-bit). We have a grid environment with 4 nodes and have grid launched workspace servers enabled (so everything runs on the grid from a local submit).
I have a process that has 10 sub processes that can run in parallel. Some take round 30 minutes and some take a few seconds. To allow the parallel execution I turned on the option under project properties / code submission to "Allow Parallel Execution on the same Server" and it runs for the most part how I'd expect. All 10 processes run at the same time.
Two things I've been struggling with however and was wondering if there is a better way or if not maybe these could be enhancements. 1. It would be nice if the program coud set the max number of jobs to run at once. I have found this number interms of what is ideal for 2 to 10 depending on how many cores you have available. So if you could set this variable within E.G. either in the project properties or in the code itself that would be a big help
2. I would like a graceful way to ENDSAS with some code. I don't think SIGNOFF is going to work because these grid launched workspace servers don't require rsubmits. When I run ENDSAS it seems to work for the most part but I get EG errors. I still get the log results and everything runs as expected so really if there was a way to suppress those E.G. errors when I run ENDSAS it maybe the best solution.
I really like this solution to grid enable jobs vs wrapping in sca code because of it's simplicity.
06-28-2016 03:59 PM
If you want better visibility for your post it would be better to open a new thread and reference the old one with a link, especially since your topic is a lot broader.