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

Hi,

 

I have added conditional processing to a program in a process flow based on the day of the month: the program should execute on the 2nd day of the month only. This works without problems when running the code from within Enterprise Guide.

 

However, now I have exported the code to a .sas file and scheduled it to run in a batch process and the condition seems to be ignored during the export. I cannot track it in the execution log and also in the created .sas file I cannot find traces of it.

 

Can anyone help me on this please? Your help is greatly appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
TomKari
Onyx | Level 15

Yes, that's exactly what I was asking about!

 

I think this should do what you need; just put the code that you want executed conditionally between the %if and the %end statements (I used a proc print step).

 

Tom

 

data _NULL_;
	rc = 0;

	if day(date()) = day('2jun2019'd) then
		rc = 1;
	CALL SYMPUT('DateFlag', PUT(rc,1.));
	stop;
run;

%if &DateFlag = 1 %then %do;

/* Code to be run conditionally */

proc print data=sashelp.class;
run;

%end;

View solution in original post

7 REPLIES 7
Haris
Lapis Lazuli | Level 10
Is it possible that your conditional processing is done in scheduler rather than SAS syntax itself? Another way SEG allows for conditional processing is via interactive user input. Can't tell how you programmed the conditional processing you're referencing.
barry_van_dijk
Obsidian | Level 7

Hello Haris,

 

Thank you for your reply!

 

The interactive user input you mentioned is not an option as the program is running as a batch in the Windows scheduler, so I cannot perform any user interaction.

 

The program just queries a database and sends an e-mail with the query results as an Ecxel attachment (see the code fragment below):

 

proc sql exec; 
	connect to odbc(datasrc="<datasource>" USER="<user>" PASSWORD="<password>"); 

	create table work.<dataset> as 
	select *
	from connection to odbc(


select
	...
from
	...
where
	...
;


)
	;

	disconnect from odbc; 
	quit; 
run; 

proc export 
data=work.<dataset>
outfile="<file path>"
dbms=xlsx replace;
run;

options emailsys = SMTP;
options emailhost = "<e-mail host>";
options emailauthprotocol = NONE;

filename anyname email
  to="<e-mail address>"
  from="<e-mail address>"
  sender="<e-mail address>"
  subject="<subject>"
  attach=("<file path>" content_type="application/xlsx");

data _null_;
 file anyname;
 put '<mail body>';
 run;

In attached zip file you will find a screenshot showing the way that the condition was added to the process flow. However, when exporting the program, this condition seems to be ignored.

 

Would you know another way to implement the condition in such a way that it gets included in the exported code?

 

Thanks, Barry

TomKari
Onyx | Level 15
I just did some experimenting, and I can't see any way to get the conditional logic into the exported SAS code.
 
However, in the program that I am running conditionally, after I've run it, there is a tab called "Conditional Logic Log". It shows how EG transitions between your specified condition and a flag that EG uses to decide whether to run the program.
 
If you're comfortable with macro logic, you should be able to use that to derive the code that you need. If not, post it here and someone will be able to give you an example.
 
Tom
barry_van_dijk
Obsidian | Level 7

Hi Tom,

 

I found the following lines in the project log:

 

1          ;*';*";*/;quit;run;
2          OPTIONS PAGENO=MIN;
3          data _NULL_; rc = 0;
4          if day(date()) = day('2jun2019'd) then
5             rc = 1;
6          CALL SYMPUT('_egrc', PUT(rc,1.));
7          stop;
8          run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
      

9          
10         QUIT; RUN;
11         

Is this what you are referring to?

 

As I am not comfortable with macro logic at all, I would be very happy if someone could help me further on this!

 

Best regards,

Barry

TomKari
Onyx | Level 15

Yes, that's exactly what I was asking about!

 

I think this should do what you need; just put the code that you want executed conditionally between the %if and the %end statements (I used a proc print step).

 

Tom

 

data _NULL_;
	rc = 0;

	if day(date()) = day('2jun2019'd) then
		rc = 1;
	CALL SYMPUT('DateFlag', PUT(rc,1.));
	stop;
run;

%if &DateFlag = 1 %then %do;

/* Code to be run conditionally */

proc print data=sashelp.class;
run;

%end;
barry_van_dijk
Obsidian | Level 7

Thank you for your reply Tom! This works for me...

 

Barry

CaseySmith
SAS Employee

As you all noted, conditional logic added to a process flow does not currently get exported as SAS code.  Manually coding conditional logic (as suggested) is the closest solution.

 

Casey


Register today and join us virtually on June 16!
sasglobalforum.com | #SASGF

View now: on-demand content for SAS users

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 2266 views
  • 1 like
  • 4 in conversation