BookmarkSubscribeRSS Feed
ghartge
Quartz | Level 8

Greetings!

 

I create and email reports from SAS EG as a step in my project. Each time the project runs and email is sent of the report or HTML output. Works great, no problem. What I would like to do is not send an email if a condition exists. Like an empty dataset or a specific value for a global macro variable. Is there a way to do this?

 

I have attempted to "Add" a "Condition" with no luck.

 

ghartge_0-1624389582324.png

 

 

Thanks,

 

Gary

8 REPLIES 8
jimbarbour
Meteorite | Level 14

Hi, @ghartge,

 

What version of EG are you running.  I'm running EG 8.2, and it seems to work fine for me.  I've used prior versions, and they too have generally worked, version 4.x being perhaps the exception.  EG wasn't really that good until version 5.1, and EG got really good with version 7.1.3 when the interactive debugger was introduced.

 

Here's my project flow.  You can see my condition opened up to the right.  You have to make sure to select the first program and "Run from selected" or only the first program will run.  The little "01" in a circle indicates the presence of a Process Flow level condition.  The "X" and the check mark indicate which program(s) run based on the condition or you can check the logs.  The logs are the ultimate arbiter of what ran and what did not.

jimbarbour_0-1624411696562.png

I have a prompt called ReturnCode.  Whatever I enter at the prompt is passed by Program1 to the next program(s).  When I enter an 8, I can see based on the logs, that Program 2 has not run but Program 3 has run.  Similarly, when I enter a 2, I can see that Program 2 has run but Program 3 has not run.

 

Frankly though, I find it easier to place return code logic inside the program instead of at the Process Flow level.  The automatic macro variable SYSCC is more or less the master return code macro variable for SAS.  I typically interogate SYSCC and then perform whatever logic is appropriate including an ABORT CANCEL if necessary.

 

Something like this:

%PUT	NOTE:  This is program 1;

%IF	%BQUOTE(&SYSCC)			=	0	%THEN
	%DO;
		%INCLUDE --Normal routine goes here--;
	%END;
%ELSE
%IF	%BQUOTE(&SYSCC)			<	8	%THEN
	%DO;
		%INCLUDE --Routine for warnings goes here--;
	%END;
%ELSE
%IF	%BQUOTE(&SYSCC)			>=	8	%THEN
	%DO;
		%INCLUDE --Routine for warnings goes here--;
	%END;

%PUT	NOTE:  Exiting with &=SYSCC;

 

Logic with multiple levels of %IF must be inside a %Macro -- %Mend wrapper.  The %BQUOTE probably isn't strictly necessary in the above example, but it's not a bad habit to be in.  If a macro variable resolves to something invalid, the %BQUOTE will prevent syntax errors.

 

Jim

ghartge
Quartz | Level 8

Thank you Jim!

I am running 7.15 HF9 (7.100.5.6226) (64-bit), sorry, I should have included that.

 

I do not believe I can use a prompt if I understand them correctly. This project is designed to run on a scheduler and so answering a prompt won't work. There is an option for using a macro variable in the Condition menu, but I cannot seem to get that to function. I set the value of the global macro variable in my program using something like;

PROC SQL;

SELECT count(course) INTO: Course_Count FROM TableName; QUIT;

 

I have attempted to add information as you have in your example, something like this (I have tried several variations);

ghartge_0-1624453458631.png

Thank you again for your help!

 

Gary

 

jimbarbour
Meteorite | Level 14

Gary,

 

The prompt was not at all to suggest that you do your Production work that way.  That was just a simple example to prove to myself and demonstrate to you that an EG condition is working.  Your example is more complex, but we'll get to that in a minute.

 

Why don't you temporarily create a little project and try my simple example?  You don't even have to use a prompt which is slightly more work.  You could use a simple %LET ReturnCode = n (where "n" is a number between 0 and 8, inclusive) in the first portion of the first program to simulate a return code.  Let's get a super simple example working.  If a super simple example doesn't work, then we know we've got some kind of EG issue.  If the super simple example does work, then we know the bug lies elsewhere.

 

Here are my three SAS programs, the crown and glory of my SAS career.  😉  Set them up as you saw in my first reply and create an EG condition.  Try two runs, making sure you "Run from selected item" or the equivalent.  Just running the first program will not run any downstream programs and will not exercise the EG condition.  The first run should be with a ReturnCode = 0 and the second run should be with a ReturnCode = 8.  Then check to see which program(s) actually executed.  

 

%PUT	NOTE:  This is program 1;

%IF	%BQUOTE(&ReturnCode)	=	%BQUOTE()	%THEN
	%DO;
		%LET	SYSCC		=	0;
	%END;
%ELSE
	%DO;
		%LET	SYSCC		=	&ReturnCode;
	%END;

%PUT	NOTE:  Exiting with &=SYSCC;
%PUT	NOTE:  Entering with &=SYSCC;

%PUT	NOTE:  This is program 2;

%PUT	NOTE:  Exiting with &=SYSCC;
%PUT	NOTE:  Entering with &=SYSCC;

%PUT	NOTE:  This is program 3;

%PUT	NOTE:  Exiting with &=SYSCC;

Jim

 

P.S.  I don't know which version of SAS you are on.  I'm using 9.4 M6.  I'm using "stand alone" (not within in a %MACRO - %MEND) %IF statements which earlier versions of SAS (prior to 9.4 M5 I think) don't support.  If you're using an earlier version of SAS, you'll have to place my code inside a %MACRO - %MEND structure and execute the macro.

ghartge
Quartz | Level 8

Good morning Jim,

 

So I am running SAS Enterprise Guide version 7.15.

I created a small project as you suggested that looks like this;

ghartge_0-1624535209477.png

Program 1 is simply this;

 

%LET ReturnCode_1 = 2;
%PUT &ReturnCode_1.;

 

Program_2 looks like this;

 

PROC SQL;
SELECT DISTINCT Term_Year, Term_Name, 'Program 2' AS Title
FROM dbo.SQL_Table
WHERE Term_Year = '2012'
ORDER BY Term_Year, Term_Name;
QUIT;

 

and Program_3 look like this;

 

PROC SQL;
SELECT DISTINCT Term_Year, Term_Name, 'Program 3' AS Title
FROM dbo.SQL_Table
WHERE Term_Year = '2013'
ORDER BY Term_Year, Term_Name;
QUIT;

 

I added this Condition to Program_2;

ghartge_1-1624535460370.png

If I set the value of &ReturnCode_1. in Program_1 to 1, Program_2 executes.

 

If I set the value of &ReturnCode_1. in Program_1 to 2, Program_3 executes.

 

This is how I would expect this to work. All good at this point.

 

If I add a "Send To" to email the results of the program that executed that doesn't function per the Condition logic. Emails of both outputs are sent.

 

ghartge_2-1624538459948.png

 

If I add the same Condition logic to the Send Email operations, both emails are still sent with different process flow conditions and both have flags. (Indicating they executed?)

ghartge_3-1624538951742.png

 

Thanks,

 

Gary

jimbarbour
Meteorite | Level 14

As far as I'm aware, you have to place the condition on each "downstream" component in the process flow.  I generally advise against using conditions at the process flow level.  Far better in my experience to execute based on macro variables in the program.  You can still use a process flow to link the various programs, but inside each program, you have conditional logic that determines which program(s) will actually run.  Your process flow can be automated in the usual Enterprise Guide fashion, but within the process flow it is the SAS programs themselves that determine which logic will be executed and which will not.  It is the SAS programs themselves that will send the email; you would not use the email functionality of Enterprise Guide.

 

In order to use a program to send an email, you would use a Filename with EMAIL following it.  There are examples if you Google it.  Inside the program, again, you would have conditional logic that determines whether to send an email (or chooses between two emails).

 

The logic would look something like the below in the email program.  I'm using &SYSCC here but you can use any macro variable or macro expression that you need to for your situation.  The logic for the programs that do the processing prior to the email would be similarly structured.

%IF  &SYSCC < 8 %THEN
    %DO;
            %INCLUDE  --normal email routine goes here--
    %END;
%ELSE
    %DO;
            %INCLUDE  --error or alternate email routine goes here--
    %END;

Jim

jimbarbour
Meteorite | Level 14

Addendum:  There is an example of SAS code to send an email from within a program in this SAS communities post:  https://communities.sas.com/t5/SAS-Enterprise-Guide/Email-from-EG-when-bandwidth-exceeded/m-p/748275...

 

It's in the last reply that I posted:  Posted 06-17-2021 11:11 PM

 

Jim

NataljaK
Obsidian | Level 7
Hi,

Sending mail using conditions works well. If that does not work , then I can assume that the conditions were not set up as they should.
ghartge
Quartz | Level 8

Thank you Nataljak.


The image below is how I set it up. Program2 and Program3 both have this condition which work as expected. The macro variable, &ReturnCode_1, is set in Program1.

ghartge_2-1625056417039.png

 

ghartge_1-1625055992753.png

 

Email is sent regardless of the condition. The conditions work fine for the selection of which program to run, but the email is sent regardless of the condition. It appears to me that the email process exists in the "Distribution" processing whereas the condition logic only applies to the "Process Flow" processing. 

 

ghartge_0-1625055854521.png

 

We use server based SAS EG and MS Office365 as our email system. Although I understand that sending email in my program is supposedly possible, I have been unable to locate in the SAS Community a version that works for our situation, yet I can send email easily via the "Send To" - - -> "Email Recipient as a step in the project" methodology.

 

Regards,

 

Gary

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