BookmarkSubscribeRSS Feed
turcay
Lapis Lazuli | Level 10

Okay, sorry for missunderstanding,

 

The Have data set is updated everyday, but it is unclear when the data set will be updated so we need to check  every half an hour.

When Final_Date and Error rows will be same then it should trigger the bat file.(This represents that the data set are ready to work for that day)

After bat file was executed, it should wait the next day until Final_Date and Error rows should be same for next day.

 

For example;

The following table will work for today, but, because scheduler works for every half an hour. I need to prevent to execute the code if it worked for that day.

 

Tabel1.png 

 

The code should wait until the table will be as below;

 

Table2.png

 

I hope I could tell you better?

 

 

turcay
Lapis Lazuli | Level 10

Hello again,

 

I updated the code, &errrcheck works which we expected, I just need to tell the code this -> "Wait or do not execute, if the code worked once for that day". How can I tell it?

 

%MACRO MAIN_LOOP;
PROC SQL ;
SELECT MAX(RESULT) INTO :errcheck FROM(SELECT *,
CASE WHEN FINAL_DATE="&SYSDATE9."D AND ERROR=0 THEN 0 ELSE 1 END AS RESULT 
FROM WANT);
QUIT;

%IF &errcheck %THEN %DO;

DATA _NULL_;
ABORT CANCEL;
RUN;

%END;
%ELSE %DO;/*I need to put a control here*/

DATA _NULL_;
CALL SYSTEM("...\Batch_Test.bat");/*EXECUTE THE BAT FILE*/
RUN;

%END;
%MEND;
%MAIN_LOOP
Kurt_Bremser
Super User

If you hand the repeating part over to the scheduler, you don't need a macro at all:

proc sql noprint;
select count(distinct final_date), max(final_date), max(error) into :datecount,:max_date,:errcheck
from want;
quit;

data _null_;
if &datecount = 1 and &max_date = today() and &errcheck = 0
/* only one date that is today, and no errors */
then call system("...\Batch_Test.bat");
else abort return 5;
run;

The scheduler just needs to run the program every 30 minutes as long as it ends with a return code of 5.

As soon as it ends with 0, execution can be suspended until the next day.

If any other return code (1 = WARNING, 2 = ERROR) happens, the scheduler should trigger the usual alert.

 

 

Edit: removed a %put that was solely for debugging.

turcay
Lapis Lazuli | Level 10

Hello Kurt,

 

Your code seems what I want, I am really much appreciated thank you.

 

I also added a code as below, will it work, what do  you think?

 

%MACRO MAIN_LOOP;

DATA WANT;
     SET HAVE;
     FINAL_DATE=DATEPART(FINAL_DATE);
     FORMAT FINAL_DATE DATE9.;
     RUN;

PROC SQL ;
SELECT MAX(RESULT) INTO :errcheck FROM(SELECT *,
CASE WHEN FINAL_DATE="&SYSDATE9."D AND ERROR=0 THEN 0 ELSE 1 END AS RESULT 
FROM WANT);
QUIT;

%IF &errcheck %THEN %DO;

DATA _NULL_;
ABORT CANCEL;
RUN;

%END;
%ELSE %DO;

DATA _NULL_;
     SET PERMANENT_LIBRARY.WANT(OBS=1);
     IF FNL_FINAL_DATE=FINAL_DATE THEN DO; ABORT CANCEL; END;
     ELSE DO;
    call system("...\Batch_Test.bat");
     END;
RUN;

 DATA PERMANENT_LIBRARY.WANT;
     SET WANT(OBS=1);
	 FNL_FINAL_DATE=FINAL_DATE;
	 FORMAT FNL_FINAL_DATE DATE9.
 RUN;
 

%END;
%MEND;
%MAIN_LOOP

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 19 replies
  • 1488 views
  • 2 likes
  • 3 in conversation