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

Greetings,

 

Just wanted to know if SAS MA can support a functionality whereby if condition A is not met then exit campaign

 

Scenario: if weekday(Today()) = 2 then continue executing proceeding logic. If  weekday(Today()) != 2 then exit campaign.

 

Thank you 😁

1 ACCEPTED SOLUTION

Accepted Solutions
JamesAnderson
SAS Employee

Hi @keiwo,

The error you are seeing is saying SAS is unhappy with the use of %IF in open code.

This is probably caused by your maintenance release - %IF only because available in open code in 9.4M5 as discussed here.

Try wrapping this up in a macro definition:

%macro EverythingsTuesday;

%let DAYOFTHEWEEK = %sysfunc(weekday(%sysfunc(Today())));
%let THERIGHTDAYOFTHEWEEK =3;

/* debug
%put &=DAYOFTHEWEEK;
%put &=THERIGHTDAYOFTHEWEEK;
*/

%if %NRQUOTE(&DAYOFTHEWEEK) ne %NRQUOTE(&THERIGHTDAYOFTHEWEEK)  %then %do ;

      %put they are not equal;
    %end ;
%mend;

%EverythingsTuesday;

Regards

James

 

 

 

View solution in original post

14 REPLIES 14
jcawesome
Obsidian | Level 7

Hi @keiwo ,

 

Yes this is possible. You just need to create a calculated variable to identify if weekday(Today()) = 2. Then in your SELECT node just use it as a selection criteria.

 

Another way of looking at this is to schedule your campaign to run only on specific days of the week. You can do this in the schedule tab in MA. Then select Schedule 'Weekly' then select which days to execute the campaign.

 

Note that MA campaigns are used to execute Batch Campaigns for generating whitelists. What's your business case for implementing such rules?

 

Hope this helps!

 

Regards,

JC

keiwo
Obsidian | Level 7

Thanks JC.

 

I was thinking maybe SAS MA would support some sort of code that I could write in a process node EXIT out of the campaign if a condition is not me and not continue on with the logic path.

 

The reason behind this ask was that campaign that was scheduled to execute on a Monday every week also executed on a Tuesday.  I checked with our IT department and they confirmed no changes were made to the scheduler. In the Execution page of SAS MA, the history tab indicated the campaign was executed by the scheduler and it was not manual.

 

very strange indeed...,

jpsm70
SAS Employee

I would check the scheduler (OSS or Platform) to see if more than one flow exists in the scheduler. 

In CI Studio, when making campaign schedule changes, the old flow should be deleted but perhaps it didn't?

shill
SAS Employee

Yes, if you set the MAError variable to a number (use something 20,000 or higher to be safe) it will force failure of the process node, which should stop the campaign from executing. You can also set MAMsg to a string that explains the error ("Nightly database update not complete, exiting", for example). Just make sure your process node is in a spot that will stop execution - having it dangling off to the side won't help - the task sequence has to go through the process node.


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

View now: on-demand content for SAS users

keiwo
Obsidian | Level 7

Would you by chance have sample code that I could use in my process node to force the campaign process to stop and EXIT ?  thank you.

JamesAnderson
SAS Employee

give this a go:

 

%let DAYOFTHEWEEK = weekday(Today());
%let THERIGHTDAYOFTHEWEEK = 2;

%if %NRQUOTE(&DAYOFTHEWEEK) ne %NRQUOTE(&THERIGHTDAYOFTHEWEEK)  %then %do ;

      %let MAMsg=ERROR: Today is not the right day of the week;

%let MAError = 20000; %let SYSCC= 20000 ; %mastatus(&_stpwork.status.txt) ; %return ; %end ;

cheers

James

keiwo
Obsidian | Level 7

Thanks James... much appreciated.

 

I created a simple test diagram to incorporate the process node code and the result was that the errorr msg appear no matter which value I assign to the variable THERIGHTDAYOFTHEWEEK.

 

Thanks for all your guidance.

******************

%let DAYOFTHEWEEK = weekday(Today());
%let THERIGHTDAYOFTHEWEEK = 2;

%if %NRQUOTE(&DAYOFTHEWEEK) ne %NRQUOTE(&THERIGHTDAYOFTHEWEEK)  %then %do ;

      %let MAMsg=ERROR: Today is not the right day of the week;      %let MAError = 20000;
      %let SYSCC= 20000 ;
      %mastatus(&_stpwork.status.txt) ;
      %return ;
    %end ;

 

data &outTable;

set &inTable;

run;

JamesAnderson
SAS Employee

this time I've tested it 😥 😀.

 

replace the first line &DAYOFTHEWEEK and then there are a couple debug statement you could use to see whats going on.

 

%let DAYOFTHEWEEK = %sysfunc(weekday(%sysfunc(Today())));
%let THERIGHTDAYOFTHEWEEK =4;
/* debug
%put &=DAYOFTHEWEEK;
%put &=THERIGHTDAYOFTHEWEEK;
*/

cheers

James

keiwo
Obsidian | Level 7

Hi James,

 

When I execute my process node, the same error msg pops up and when I check the log details I see the following info

Is there a particular syntax I need to follow if an %IF statement is used ?  Thanks.

 

/******* PROCESS NODE LOG ******/

102       +%let DAYOFTHEWEEK = %sysfunc(weekday(%sysfunc(Today())));
103       +%let THERIGHTDAYOFTHEWEEK =4;
104       +/* debug
105       +*%put &=DAYOFTHEWEEK;
106       +*%put &=THERIGHTDAYOFTHEWEEK;
107       +*/
108       +%if &DAYOFTHEWEEK ne &THERIGHTDAYOFTHEWEEK  %then %do ;
ERROR: The %IF statement is not valid in open code.
109       +%let MAMsg=ERROR: Today is not the right day of the week;
110       +%let MAError = 20000;
111       +%let SYSCC= 20000 ;
112       +%mastatus(&_stpwork.status.txt) ;
Return Status in process 8557:
SYSCC=20000
MAError=20000
MAMsg=ERROR: Today is not the right day of the week

 

 

/************** PROCESS NODE CODE ***************/

%let DAYOFTHEWEEK = %sysfunc(weekday(%sysfunc(Today())));
%let THERIGHTDAYOFTHEWEEK =4;
/* debug
*%put &=DAYOFTHEWEEK;
*%put &=THERIGHTDAYOFTHEWEEK;
*/
%if &DAYOFTHEWEEK ne &THERIGHTDAYOFTHEWEEK  %then %do ;
      %let MAMsg=ERROR: Today is not the right day of the week;     
      %let MAError = 20000;
      %let SYSCC= 20000 ;
      %mastatus(&_stpwork.status.txt) ;
      %return ;
    %end ;
 
data &outTable;
set &inTable;
run;
 
 
/*---------------------------------------------------------------------------
|  count the number of subjects in the output
+--------------------------------------------------------------------------*/
%macount(&outTable);
jcawesome
Obsidian | Level 7

Hi @keiwo ,

 

I tried it on my side. @JamesAnderson 's code works. See screenshots below.

Screenshot1 shows the code without place the the Error statement with counts shown.

screenshot1.png

 Screenshot2 shows a successful run since the dayoftheweek = therightdayoftheweek.

screenshot2.png

 Screenshot3 shows an error since I changed the value of the rightdayoftheweek to 3.

screenshot3.png

 Screenshot4 shows the same error in the campaign diagram when I tried to update count.

screenshot4.png

 Screenshot5 shows the log with the %put statement showing the values of the macros.

screenshot5.png

 

Please do share any screenshots of the diagram if there are still any errors.

 

I hope this helps. 🙂

 

Regards,

JC

keiwo
Obsidian | Level 7

Hi James,

 

much appreciated for all your time.  I used the same code as you, however, when I execute my process node, I still receive the error msg that weekday(today()) is not equal to 6 (Friday)

 

My SAS CI version is 6.5 hotfix 01

 

**************
Below is the process node log details

 

102       +%let DAYOFTHEWEEK = %sysfunc(weekday(%sysfunc(Today())));
103       +%let THERIGHTDAYOFTHEWEEK=6;
104       +/* debug */
105       +%put &=DAYOFTHEWEEK;
DAYOFTHEWEEK=6
106       +%put &=THERIGHTDAYOFTHEWEEK;
THERIGHTDAYOFTHEWEEK=6
107       +%if &DAYOFTHEWEEK ne &THERIGHTDAYOFTHEWEEK  %then %do ;
ERROR: The %IF statement is not valid in open code.
108       +%let MAMsg=ERROR: Today is not the right day of the week;
109       +%let MAError = 20000;
110       +%let SYSCC= 20000 ;
111       +%mastatus(&_stpwork.status.txt) ;
Return Status in process 8557:

 

jcawesome
Obsidian | Level 7

Hi @keiwo,

 

Have you tried running the macro script in SAS EG? Can you share the results with screenshots after changing the value (i.e.changing the value from 1 to 7) %let THERIGHTDAYOFTHEWEEK=(value)?

 

Also, maybe you might need to check the server date and time in your server. Is it in sync with the correct date and time?

 

Regards,

JC

JamesAnderson
SAS Employee

Hi @keiwo,

The error you are seeing is saying SAS is unhappy with the use of %IF in open code.

This is probably caused by your maintenance release - %IF only because available in open code in 9.4M5 as discussed here.

Try wrapping this up in a macro definition:

%macro EverythingsTuesday;

%let DAYOFTHEWEEK = %sysfunc(weekday(%sysfunc(Today())));
%let THERIGHTDAYOFTHEWEEK =3;

/* debug
%put &=DAYOFTHEWEEK;
%put &=THERIGHTDAYOFTHEWEEK;
*/

%if %NRQUOTE(&DAYOFTHEWEEK) ne %NRQUOTE(&THERIGHTDAYOFTHEWEEK)  %then %do ;

      %put they are not equal;
    %end ;
%mend;

%EverythingsTuesday;

Regards

James

 

 

 

keiwo
Obsidian | Level 7
HI James,

My apologies for the late reply. Out IT just upgraded our SASCI form version 6.5 to v6.6 this week. I had the opportunity to test out your code once again and it does work.

Thanks so much for your patience and understanding. I can now share this knowledge with the rest of my colleagues.

🙂
How to improve email deliverability

SAS' Peter Ansbacher shows you how to use the dashboard in SAS Customer Intelligence 360 for better results.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 14 replies
  • 2361 views
  • 5 likes
  • 5 in conversation