<?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: Schedule a sas program to trigger shell script in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-shell-script/m-p/440499#M110042</link>
    <description>&lt;P&gt;You CANNOT(!) influence data step variables with code in a call execute, as that code will run AFTER(!) the current data step has finished, and won't do anything before that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Go back to square one, and define your problem/task in plain language. Then select the proper tools (which IMO won't include SAS for most of the work), then start coding.&lt;/P&gt;</description>
    <pubDate>Tue, 27 Feb 2018 13:37:01 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-02-27T13:37:01Z</dc:date>
    <item>
      <title>Schedule a sas program to trigger shell script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-shell-script/m-p/440454#M110029</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Date_test();

PROC SQL;
CONNECT TO TERADATA(details) ;
CREATE TABLE MAX01 AS
SELECT * FROM CONNECTION TO TERADATA
(
SELECT max(date_col) as d, current_date-1 as curr_date from table;
);
QUIT;



PROC SQL;
SELECT d format=YYMMDD10. ,curr_date format=YYMMDD10. into: max_dt, : cur_dt  FROM MAX01;
quit;

%put &amp;amp;max_dt &amp;amp;cur_dt;


%mend Date_test;


data _null_;

do i=1 to 5 while (i lt 5);

     if &amp;amp;max_dt. = &amp;amp;cur_dt. then do;
        call system('Sample.ksh');
         i+10;
	 end;
else do;
	 x = sleep(3600,1);
	 call execute ('%Date_test();');
     end;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am new to SAS. &amp;nbsp;The intention of the program is to trigger a shell script if yesterday's data load is complete. If not sleep for an hour until 4 hours to check again and again to run the shell script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First part of the program is a macro to check for the max date and current date -1 from database and store it in a macro variable. In a ideal scenario these both should be equal. For eg, if I run it today (27th Feb), it should be 26th Feb for both.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Second part is Data _null_ step to check the condition in IF part and trigger the shell script. Else, sleep for 1 hour and then run the macro again and begin with Do loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am unsure about the following:&lt;/P&gt;&lt;P&gt;1.Here, how do I pass the max_dt and curr_dt back to Data _null_ step?&lt;/P&gt;&lt;P&gt;2. The shell script is not getting triggered using Call system command. How do I make this work? I have tried using sysexec and Filename commands already.&lt;/P&gt;&lt;P&gt;3. Any loopholes that I am missing here..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot for your help!&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2018 11:17:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-shell-script/m-p/440454#M110029</guid>
      <dc:creator>visa</dc:creator>
      <dc:date>2018-02-27T11:17:58Z</dc:date>
    </item>
    <item>
      <title>Re: Schedule a sas program to trigger shell script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-shell-script/m-p/440493#M110039</link>
      <description>&lt;P&gt;These macro references:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;max_dt&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;cur_dt&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; do&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will be resolved exactly &lt;EM&gt;once&lt;/EM&gt;, when the data step is compiled, and will never change during data step execution. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your attempt to call SQL inside a data step will not work, the code called with call execute will only start to run once the data step has &lt;EM&gt;finished&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why don't you write a simple SAS program that checks a dataset and exits with a given return code, depending on your condition, and evaluate that in a shell script?&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2018 13:05:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-shell-script/m-p/440493#M110039</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-02-27T13:05:13Z</dc:date>
    </item>
    <item>
      <title>Re: Schedule a sas program to trigger shell script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-shell-script/m-p/440496#M110041</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;Thanks for your response. Would this make a difference? Assigning a global variable and calling the macro at the beginning of DO loop? Also can you please expand on what you're suggesting below?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global max_dt cur_dt;

%macro Date_test();

PROC SQL;
CONNECT TO TERADATA(details) ;
CREATE TABLE MAX01 AS
SELECT * FROM CONNECTION TO TERADATA
(
SELECT max(date_col) as d, current_date-1 as curr_date from table;
);
QUIT;



PROC SQL;
SELECT d format=YYMMDD10. ,curr_date format=YYMMDD10. into: max_dt, : cur_dt  FROM MAX01;
quit;


%put &amp;amp;max_dt &amp;amp;cur_dt;
%let max_dt= &amp;amp;max_dt.;
%let cur_dt= &amp;amp;cur_dt.;


%mend Date_test;

data _null_;

do i=1 to 5 while (i lt 5);
call execute ('%Date_test();');
     if max_dt = cur_dt then do;
        call system('Sample.ksh');
         i+10;
	 end;
else 
	x = sleep(3600,1);
end;
run;








&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2018 13:35:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-shell-script/m-p/440496#M110041</guid>
      <dc:creator>visa</dc:creator>
      <dc:date>2018-02-27T13:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: Schedule a sas program to trigger shell script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-shell-script/m-p/440499#M110042</link>
      <description>&lt;P&gt;You CANNOT(!) influence data step variables with code in a call execute, as that code will run AFTER(!) the current data step has finished, and won't do anything before that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Go back to square one, and define your problem/task in plain language. Then select the proper tools (which IMO won't include SAS for most of the work), then start coding.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2018 13:37:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-shell-script/m-p/440499#M110042</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-02-27T13:37:01Z</dc:date>
    </item>
    <item>
      <title>Re: Schedule a sas program to trigger shell script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-shell-script/m-p/440616#M110110</link>
      <description>&lt;P&gt;The issue is you did not call the macro before executing data step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And your approach is wrong.&amp;nbsp; I have made few corrections. Please close a post before re-posting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a fix. And also keep in mind the things&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13728"&gt;@SASJedi&lt;/a&gt;&amp;nbsp; &amp;nbsp;mentioned in his answer to your another question.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let us know if it helped.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Date_test(itration=); 
	%do i = 1 %to &amp;amp;itration.;
		PROC SQL; 
		CONNECT TO TERADATA(details) ; 
		CREATE TABLE MAX01 AS SELECT * FROM CONNECTION TO TERADATA 
		( SELECT max(date_col) as d, current_date-1 as curr_date from table; ); 
		QUIT; 　 　 
		
		PROC SQL; 
		SELECT d - curr_date into: diff 
		FROM MAX01; 
		quit; 
		
		data _null_; 
			if &amp;amp;diff.=0 then do; 
				call system('Sample.ksh'); 
			end; 
			else do; 
				x = sleep(3600,1); 
				call execute ('%Date_test();'); 
			end;  
		run;
	%end;
%mend Date_test; 　 
%Date_test(itration=7); /*7 iterations each having sleep of 1 hour*/&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Feb 2018 18:14:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-shell-script/m-p/440616#M110110</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2018-02-27T18:14:15Z</dc:date>
    </item>
    <item>
      <title>Re: Schedule a sas program to trigger shell script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-shell-script/m-p/448950#M112942</link>
      <description>&lt;P&gt;can you please let me know how it will understand the ksh path&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 12:34:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-shell-script/m-p/448950#M112942</guid>
      <dc:creator>sandeep90</dc:creator>
      <dc:date>2018-03-27T12:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: Schedule a sas program to trigger shell script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-shell-script/m-p/448964#M112946</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/201385"&gt;@sandeep90&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;can you please let me know how it will understand the ksh path&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It does not need to. The Korn Shell script will have a "shebang" at the start:&lt;/P&gt;
&lt;PRE&gt;#!/usr/bin/ksh&lt;/PRE&gt;
&lt;P&gt;which tells the system which program should be used to run it.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 13:14:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-shell-script/m-p/448964#M112946</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-27T13:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: Schedule a sas program to trigger shell script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-shell-script/m-p/449241#M113039</link>
      <description>Thank you so much</description>
      <pubDate>Wed, 28 Mar 2018 08:06:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-shell-script/m-p/449241#M113039</guid>
      <dc:creator>sandeep90</dc:creator>
      <dc:date>2018-03-28T08:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: Schedule a sas program to trigger shell script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-shell-script/m-p/449247#M113042</link>
      <description>&lt;P&gt;You can provide the path here instated of only file name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;call &lt;SPAN class="token function"&gt;system&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'/dev/user/sandeep/Sample.ksh'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Mar 2018 09:13:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-shell-script/m-p/449247#M113042</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2018-03-28T09:13:39Z</dc:date>
    </item>
  </channel>
</rss>

