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!
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;
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
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
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;
Thank you for your reply Tom! This works for me...
Barry
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
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.