<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to - Trigger a BAT File After a Job Finish by SAS Code? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430080#M106291</link>
    <description>&lt;P&gt;Change the %do statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do %until (0);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 23 Jan 2018 17:00:53 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-01-23T17:00:53Z</dc:date>
    <item>
      <title>How to - Trigger a BAT File After a Job Finish by SAS Code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/429995#M106245</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a data set as below and it feeds from IT department.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If whole FINAL_DATE rows include “date of the day”(for example -&amp;gt; 23JAN2018) and whole ERROR rows are equal to zero then it should trigger a .bat file.&lt;/P&gt;
&lt;P&gt;To do this, I need IF-ELSE control structures and it should control every half an hour. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;After it started the bat file, to prevent to execute the code until the next day, I need an another IF-ELSE control structure.&lt;/P&gt;
&lt;P&gt;At this point, I need your help. Can someone help me about this, please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Length FINAL_DATE 8 ERROR 8;
Infile Datalines Missover;
Input FINAL_DATE ERROR ;
FORMAT FINAL_DATE  DATE9.;
Datalines;
21207 0
21207 0
21207 0
21207 0
21207 0
21207 0
21207 0
21207 0
21207 0
21207 0
21207 0
;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To Trigger a BAT file, I have this;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data _Null_;
X "......\Batch.bat";
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2018 14:22:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/429995#M106245</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2018-01-23T14:22:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Trigger a BAT File After a Job Finish by SAS Code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430023#M106263</link>
      <description>&lt;P&gt;This looks like a task for the original scheduler that your IT uses. They should simply run the batch when all your jobs have their condition OK. A very simple task for them, using the proper tools for the job.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2018 15:20:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430023#M106263</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-23T15:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Trigger a BAT File After a Job Finish by SAS Code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430026#M106265</link>
      <description>&lt;P&gt;Firstly, thank you for your time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm agree with you but what if I have to do this in SAS environment. Aren't there any ways to do in SAS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2018 15:22:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430026#M106265</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2018-01-23T15:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Trigger a BAT File After a Job Finish by SAS Code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430060#M106279</link>
      <description>&lt;P&gt;I suggest an indefinitely looping macro that checks, and then either sleeps for 30 minutes or executes the shell script/bat and sleeps until next day:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro main_loop;
%do %until 0;

  proc sql noprint;
  select max(error) into :errcheck from have where final_date = "....";
  quit;

  %if &amp;amp;errcheck
  %then %do;

    data _null_;
    x = sleep(1800,1);
    run;

  %end;
  %else %do;

    data _null_;
    call system("....bat");
    now = datetime();
    tomorrow = intnx('dtday',now,1,'b');
    sleeptime = tomporrow - now;
    x = sleep(sleeptime,1);
    run;

  %end;

%end;
%mend;

%main_loop  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Jan 2018 16:12:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430060#M106279</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-23T16:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Trigger a BAT File After a Job Finish by SAS Code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430076#M106288</link>
      <description>&lt;P&gt;Thank you for your time again but it gives errors as below, I do not understand the reason.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: Expected parenthesis not found after UNTIL.&lt;/P&gt;
&lt;P&gt;ERROR: A dummy macro will be compiled.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 180&lt;/P&gt;
&lt;P&gt;WARNING: Apparent invocation of macro MAIN_LOOP not resolved.&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2018 16:38:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430076#M106288</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2018-01-23T16:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Trigger a BAT File After a Job Finish by SAS Code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430080#M106291</link>
      <description>&lt;P&gt;Change the %do statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do %until (0);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Jan 2018 17:00:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430080#M106291</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-23T17:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Trigger a BAT File After a Job Finish by SAS Code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430096#M106295</link>
      <description>&lt;P&gt;in conclusion, What do we provide by writing&amp;nbsp; %DO %UNTIL (0) ; statement? Can you explain me, shortly?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2018 17:54:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430096#M106295</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2018-01-23T17:54:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Trigger a BAT File After a Job Finish by SAS Code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430106#M106299</link>
      <description>&lt;P&gt;As Kurt mentioned, %do %until(0) will create an infinite loop.&amp;nbsp; That is, the loop will keep iterating for ever, because 0 is false.&amp;nbsp; So %until condition will never become true, and the loop will keep iterating for ever.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2018 18:19:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430106#M106299</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2018-01-23T18:19:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Trigger a BAT File After a Job Finish by SAS Code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430116#M106303</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/48505"&gt;@turcay&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;in conclusion, What do we provide by writing&amp;nbsp; %DO %UNTIL (0) ; statement? Can you explain me, shortly?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The logical value "true" is represented by a numeric value 1, and "false" is 0. You could use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do %while (1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;for the same purpose.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2018 18:49:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430116#M106303</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-23T18:49:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Trigger a BAT File After a Job Finish by SAS Code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430498#M106411</link>
      <description>&lt;P&gt;Hello again,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your explanation. It is more clear now.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have one more question now. The table HAVE is fed as DATETIME, I mean the variable FINAL_DATE has a format DATETIME21. So I put the following&amp;nbsp; code into your macro.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  DATA WANT;
     SET HAVE;
     FINAL_DATE=DATEPART(FINAL_DATE);
     FORMAT FINAL_DATE DATE9.;
     RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then it was like this -&amp;gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO main_loop;
%do %until (0);
 
     DATA WANT;
     SET HAVE;
     FINAL_DATE=DATEPART(FINAL_DATE);
     FORMAT FINAL_DATE DATE9.;
     RUN;
 
  proc sql noprint;
  select max(ERROR) into :errcheck from WANT where FINAL_DATE = "&amp;amp;SYSDATE9."D;
  quit;
 
  %if &amp;amp;errcheck
  %then %do;
 
    data _null_;
   x = sleep(1800,1);/*Wait until 1800 seconds*/
    run;
 
  %end;
  %else %do;
 
    data _null_;
    call system("...\Batch_Test.bat");/*EXECUTE THE BAT FILE*/
    now = datetime();/*Give that date and time*/
    tomorrow = intnx('dtday',now,1,'b');/*'b'-&amp;gt; beginning*//*Next day*/
    sleeptime = tomorrow - now;
    x = sleep(sleeptime,1);
    run;
 
  %end;
 
%end;
%MEND;
 
%main_loop
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I wonder is it stilll work after my addtional step into macro?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In addition, I execute this code&amp;nbsp;by calling new BAT file. IT can execute the code every 30 minutes by the help of Windows Scheduler. Can&amp;nbsp;that make our macro code easier?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;Can Yılmazer&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 07:35:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430498#M106411</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2018-01-25T07:35:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Trigger a BAT File After a Job Finish by SAS Code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430544#M106424</link>
      <description>&lt;P&gt;Of course, running the code regularly off the scheduler will make it easier, as the indefinite loop is not needed. You might want to work with manually setting the return code, so that the scheduler can decide if the code needs to be rerun for a given date.&lt;/P&gt;
&lt;P&gt;Your code addition looks fine to me.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 17:06:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430544#M106424</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-24T17:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Trigger a BAT File After a Job Finish by SAS Code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430794#M106498</link>
      <description>&lt;P&gt;Hello Kurt,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your time again. So the following code and Scheduler(Every half an hour) will be enough for this process? On the other hand, what if somebody open the WANT data set, while the code was working in background. There can be lock error? Any method to prevent this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO main_loop;

DATA WANT;
     SET HAVE;
     FINAL_DATE=DATEPART(FINAL_DATE);
     FORMAT FINAL_DATE DATE9.;
     RUN;
 
  proc sql noprint;
  select max(ERROR) into :errcheck from WANT where FINAL_DATE = "&amp;amp;SYSDATE9."D;
  quit;
 
  %if &amp;amp;errcheck
  %then %do;
 
    data _null_;
   x = sleep(1800,1);/*Wait until 1800 seconds*/
    run;
 
  %end;
  %else %do;
 
    data _null_;
    call system("C:\Users\sas.c.yilmazer\Documents\BATCHTEST\Batch_Test.bat");/*EXECUTE THE BAT FILE*/
    now = datetime();/*Give that date and time*/
    tomorrow = intnx('dtday',now,1,'b');/*'b'-&amp;gt; beginning*//*Next day*/
    sleeptime = tomorrow - now;
    x = sleep(sleeptime,1);
    run;
 
  %end;

%MEND;
 
%main_loop&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you,&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 07:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430794#M106498</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2018-01-25T07:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Trigger a BAT File After a Job Finish by SAS Code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430805#M106501</link>
      <description>&lt;P&gt;It's very hard (basically impossible) for somebody to open your want dataset, as it's in the WORK directory of the SAS process. WORK directories are readable only by the owning user (or the superuser, but that's a given), and they have the process number coded in their name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In order to inspect people's WORK data, I have to log in as superuser, find the directory according to owner/process number, and copy the .sas7bdat in question to a location where I can pick it up with my personal workspace server session. That's a highly administrative task.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since your code will now be triggered by the scheduler, the sleep() functions are not necessary anymore (there's also no looping).&lt;/P&gt;
&lt;P&gt;Instead you should set a specific exit code that tells the scheduler how to proceed further. You can do this with the abort statement in a data _null_ step.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 08:18:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430805#M106501</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-25T08:18:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Trigger a BAT File After a Job Finish by SAS Code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430819#M106502</link>
      <description>&lt;P&gt;Thank you for detail explanation again,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I realized something so I have few more questions to you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Firstly, if Final_Date rows can be different with each other,&amp;nbsp;&amp;amp;errcheck still returns zero, shouldn't it return 1? Because every Final_Date rows and every ERROR rows should be same to trigger the code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a sample which returns 0 even Final_Date rows are different;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Want;
Length FINAL_DATE 8 ERROR 8;
Infile Datalines Missover;
Input FINAL_DATE ERROR ;
FORMAT FINAL_DATE  DATE9.;
Datalines;
21208 0
21208 0
21208 0
21209 0
21209 0
21209 0
21209 0
21209 0
21209 0
21209 0
21209 0
;
Run;
PROC SQL NOPRINT;
  SELECT MAX(ERROR) INTO :errcheck FROM WANT WHERE FINAL_DATE = "&amp;amp;SYSDATE9."D;
QUIT;
  %PUT &amp;amp;errcheck.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For my second problem, let's pretend we solved the foregoing Final_Date problem. If the code is executed in that today, how can I tell the code, it should wait until nextday &amp;amp;errcheck variable will be 0? Can you help about it?&lt;/P&gt;
&lt;P&gt;By the way, I put the Abort variable as below;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO main_loop;
 
PROC SQL NOPRINT;
  SELECT MAX(ERROR) INTO :errcheck FROM WANT WHERE FINAL_DATE = "&amp;amp;SYSDATE9."D;
QUIT;
 
  %IF &amp;amp;errcheck
  %THEN %DO;

  DATA _NULL_;
  ABORT CANCEL;
  RUN;

  %END;
  %ELSE %DO;
 
    data _null_;
    call system("...\Batch_Test.bat");/*EXECUTE THE BAT FILE*/
    run;
 
  %END;

%MEND;
 
%main_loop&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 08:58:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430819#M106502</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2018-01-25T08:58:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Trigger a BAT File After a Job Finish by SAS Code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430823#M106503</link>
      <description>&lt;P&gt;We're tinkering around with code without really knowing the issue at hand.&lt;/P&gt;
&lt;P&gt;Please define (clearly)&lt;/P&gt;
&lt;P&gt;- which data you receive, and when&lt;/P&gt;
&lt;P&gt;- which action needs to be taken, under which conditions present in the data&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 09:13:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430823#M106503</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-25T09:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Trigger a BAT File After a Job Finish by SAS Code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430829#M106505</link>
      <description>&lt;P&gt;Okay, sorry for missunderstanding,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Have data set is updated everyday, but&amp;nbsp;it is unclear when the data set will be updated so we need to check&amp;nbsp; every half an hour.&lt;/P&gt;
&lt;P&gt;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)&lt;/P&gt;
&lt;P&gt;After bat file was executed, it should wait the next day until&amp;nbsp;&lt;SPAN&gt;Final_Date and Error rows should be same for next day.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;For example;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The following table will work for today, but, because scheduler works for every half an hour. I need to prevent to execute the code&amp;nbsp;if it worked for that day.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tabel1.png" style="width: 227px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18095i2B57E661F6A1F36C/image-dimensions/227x214?v=v2" width="227" height="214" role="button" title="Tabel1.png" alt="Tabel1.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The code should wait&amp;nbsp;until the table will be as below;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Table2.png" style="width: 254px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18096iD4EF5BA276B9456F/image-size/large?v=v2&amp;amp;px=999" role="button" title="Table2.png" alt="Table2.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I hope I could tell you better?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 10:29:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430829#M106505</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2018-01-25T10:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Trigger a BAT File After a Job Finish by SAS Code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430852#M106509</link>
      <description>&lt;P&gt;Hello again,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I updated the code, &amp;amp;errrcheck works which we expected, I just need to tell the code this -&amp;gt; "Wait or do not execute, if the code worked once for that day". How can I tell it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO MAIN_LOOP;
PROC SQL ;
SELECT MAX(RESULT) INTO :errcheck FROM(SELECT *,
CASE WHEN FINAL_DATE="&amp;amp;SYSDATE9."D AND ERROR=0 THEN 0 ELSE 1 END AS RESULT 
FROM WANT);
QUIT;

%IF &amp;amp;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&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jan 2018 11:07:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430852#M106509</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2018-01-25T11:07:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Trigger a BAT File After a Job Finish by SAS Code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430929#M106535</link>
      <description>&lt;P&gt;If you hand the repeating part over to the scheduler, you don't need a macro at all:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select count(distinct final_date), max(final_date), max(error) into :datecount,:max_date,:errcheck
from want;
quit;

data _null_;
if &amp;amp;datecount = 1 and &amp;amp;max_date = today() and &amp;amp;errcheck = 0
/* only one date that is today, and no errors */
then call system("...\Batch_Test.bat");
else abort return 5;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The scheduler just needs to run the program every 30 minutes as long as it ends with a return code of 5.&lt;/P&gt;
&lt;P&gt;As soon as it ends with 0, execution can be suspended until the next day.&lt;/P&gt;
&lt;P&gt;If any other return code (1 = WARNING, 2 = ERROR) happens, the scheduler should trigger the usual alert.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: removed a %put that was solely for debugging.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 14:41:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430929#M106535</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-25T14:41:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Trigger a BAT File After a Job Finish by SAS Code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430956#M106545</link>
      <description>&lt;P&gt;Hello Kurt,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code seems what I want, I am really much appreciated thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also added a code as below, will it work, what do&amp;nbsp; you think?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%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="&amp;amp;SYSDATE9."D AND ERROR=0 THEN 0 ELSE 1 END AS RESULT 
FROM WANT);
QUIT;

%IF &amp;amp;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&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jan 2018 15:30:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430956#M106545</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2018-01-25T15:30:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Trigger a BAT File After a Job Finish by SAS Code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430977#M106551</link>
      <description>&lt;P&gt;Try it.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 16:21:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Trigger-a-BAT-File-After-a-Job-Finish-by-SAS-Code/m-p/430977#M106551</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-25T16:21:06Z</dc:date>
    </item>
  </channel>
</rss>

