<?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 a shell script in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-a-shell-script/m-p/440799#M110200</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13728"&gt;@SASJedi&lt;/a&gt;&amp;nbsp;Thank you very much.&lt;/P&gt;&lt;P&gt;I wrote a dummy sas program(like below)&amp;nbsp;to just trigger the Shell script and it worked. That is why I went ahead and used it in the original program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call system ('abc.ksh');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the Symget function and DOSUBL(), I was able to run the script without any errors.&lt;/P&gt;&lt;P&gt;Thank you very much for your detailed explanation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am still working on the Call System part to trigger the shell script - The log file gets locked for a long time and the shell never gets invoked when used with the program. I will update about that briefly.&lt;/P&gt;</description>
    <pubDate>Wed, 28 Feb 2018 08:48:30 GMT</pubDate>
    <dc:creator>visa</dc:creator>
    <dc:date>2018-02-28T08:48:30Z</dc:date>
    <item>
      <title>Schedule a sas program to trigger a shell script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-a-shell-script/m-p/440445#M110021</link>
      <description>&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;I am new to SAS. The requirement is to trigger a shell script based on the data load. If the data&amp;nbsp;is present for the previous date, then trigger the shell script. Else wait for one&amp;nbsp;hour, check the date again and then on a loop for&amp;nbsp;four times. &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;The&amp;nbsp;first part&amp;nbsp;of the code is a macro. This macro connects to the database, pulls in two values - Maximum date present and Current date -1. In a ideal scenario, both dates should be same. Like for today(27th Feb), both should be 26th Feb. Then&amp;nbsp;I am storing it in two macro variables. &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;The second part checks the condition in IF part,&amp;nbsp;if the dates are not equal, it sleeps for an hour, calls the macro again (to check for data load) and then&amp;nbsp;goes to the beginning part of DO loop. In the IF part if it matches, then triggers the shell script, increments the 'i' and gets out of the loop. This is my intention of writing the program.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;Following are the issues&amp;nbsp;I am facing:&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;1. How to&amp;nbsp;return the Max_Dt and Cur_Dt macro variables back to the Data _null_ step every time the macro is triggered? I am facing an error when I try to use the macro variables back in Data -null_ step.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference MAX_DT not resolved.&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference CUR_DT not resolved.&lt;/P&gt;&lt;P&gt;ERROR 386-185: Expecting an arithmetic expression.&lt;/P&gt;&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;2. I am not able to trigger the shell &amp;nbsp;the shell script using the Call system command. The log file gets locked, but the shell script never gets invoked. The shell script basically defines triggers a set of sas reports with a defined location for Output and Log files. &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;3. What are the other loopholes that I might be missing here?&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;I really appreciate any suggestions to make this code more robust. I have used SAS EG 7.1 and also through Unix to trigger this program.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&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;/STRONG&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Feb 2018 10:49:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-a-shell-script/m-p/440445#M110021</guid>
      <dc:creator>visa</dc:creator>
      <dc:date>2018-02-27T10:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: Schedule a sas program to trigger a shell script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-a-shell-script/m-p/440503#M110043</link>
      <description>&lt;P&gt;Before attempting to do something like this, you should first ensure that your SAS workspace server is configured to allow execution of shell script commands from SAS. Although is it possible, it's not the default configuration. Without proper configuration of the workspace server, it is not possible to execute shell scripts from SAS using Enterprise Guide. See the article "&lt;A href="https://blogs.sas.com/content/sasdummy/2009/11/19/using-the-x-and-systask-commands-from-sas-enterprise-guide/" target="_self"&gt;Using the X and SYSTASK commands from SAS Enterprise Guide&lt;/A&gt;" for information.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next - the execution of your macro is what produces and populates the macro variables&amp;nbsp;max_dt cur_dt. Those variables will not exist yet at the time your DATA step executes (the macro&amp;nbsp;is called by the DATA step, so it hasn't executed yet). Because the DATA step code includes references to those values (&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;if &amp;amp;max_dt.=&amp;amp;cur_dt. then&amp;nbsp;do;&lt;/FONT&gt;&lt;/STRONG&gt;), the macro processor attempts to resolve the variables during tokenization of the DATA step&amp;nbsp;for compilation.&amp;nbsp; This is why you are getting&amp;nbsp;these warnings and errors:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;WARNING: Apparent symbolic reference MAX_DT not resolved.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;WARNING: Apparent symbolic reference CUR_DT not resolved.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;ERROR 386-185: Expecting an arithmetic expression.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This problem could be circumvented by reading the values from the macro symbol table at execution time with the SYMGET function:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;if symget('max_dt')=symget('cur_dt') then&amp;nbsp;do;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next, macro calls generated by a DATA step using CALL EXECUTE stack code in the input stack while the DATA step is still running,&amp;nbsp;whic will only execute after the DATA step completes execution. Take a look at &lt;A href="http://go.documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p09dcftd1xxg1kn1brnjyc0q93yk.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;DOSUBL()&lt;/A&gt; as an alternative which allows immediate execution of the generated code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2018 13:58:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-a-shell-script/m-p/440503#M110043</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2018-02-27T13:58:19Z</dc:date>
    </item>
    <item>
      <title>Re: Schedule a sas program to trigger a shell script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-a-shell-script/m-p/440602#M110097</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;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13728"&gt;@SASJedi&lt;/a&gt;&amp;nbsp;mentioned in his answer to the question.&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:07:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-a-shell-script/m-p/440602#M110097</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2018-02-27T18:07:00Z</dc:date>
    </item>
    <item>
      <title>Re: Schedule a sas program to trigger a shell script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-a-shell-script/m-p/440799#M110200</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13728"&gt;@SASJedi&lt;/a&gt;&amp;nbsp;Thank you very much.&lt;/P&gt;&lt;P&gt;I wrote a dummy sas program(like below)&amp;nbsp;to just trigger the Shell script and it worked. That is why I went ahead and used it in the original program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call system ('abc.ksh');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the Symget function and DOSUBL(), I was able to run the script without any errors.&lt;/P&gt;&lt;P&gt;Thank you very much for your detailed explanation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am still working on the Call System part to trigger the shell script - The log file gets locked for a long time and the shell never gets invoked when used with the program. I will update about that briefly.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2018 08:48:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-a-shell-script/m-p/440799#M110200</guid>
      <dc:creator>visa</dc:creator>
      <dc:date>2018-02-28T08:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: Schedule a sas program to trigger a shell script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-a-shell-script/m-p/441001#M110264</link>
      <description>&lt;P&gt;SAS system option&amp;nbsp;&amp;nbsp;XWAIT might be the problem. XWAIT waits for the user to enter&amp;nbsp;EXIT on the command line in the shell script window before exiting and returning control to SAS. Try adding EXIT to the end of your shell script...&lt;/P&gt;
&lt;P&gt;Mark&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2018 20:12:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-a-shell-script/m-p/441001#M110264</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2018-02-28T20:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: Schedule a sas program to trigger a shell script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-a-shell-script/m-p/441017#M110267</link>
      <description>&lt;P&gt;I really think this would be better handled without using macro variables.&amp;nbsp; I'd just create a PROC SQL view I could test to see if the dates matched, then do it all in a data step. Fewer moving parts and easier to troubleshoot:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;PROC SQL ;
   connect to TERADATA(details);
   create VIEW MAX01 AS 
      select max_date format=mmddyy10., curr_date format=mmddyy10.
         from connection to teradata 
         (SELECT max(date_col) as max_date, current_date-1 as curr_date from table; );
   disconnect from teradata;
quit;

/*********************************************************************
 Read the view, always specifying observation #1. This will prevent 
 the DATA step from ever seeing end of file, so it will keep running
 until it sees a STOP statement.
*********************************************************************/
data _null_;
   n=1;
   do i=1 to 6 while ( i &amp;lt; 6);
/*********************************************************************
 Read the view, test to see if the dates match.
*********************************************************************/
      set work.max01 point=n;
/*********************************************************************
 If they match, execute the script
*********************************************************************/
      if max_date = curr_date then
         do;
            call system('c:\temp\sample.bat');
            stop;
         end;
/*********************************************************************
 Otherwise, sleep then try again.
*********************************************************************/
      else
         do;
            x = sleep(3600,1);
            /* This stop just ensures the SAS program doesn't run forever */
            if i=6 then stop; 
         end;
   end;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Feb 2018 20:58:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-a-shell-script/m-p/441017#M110267</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2018-02-28T20:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: Schedule a sas program to trigger a shell script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-a-shell-script/m-p/442267#M110634</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13728"&gt;@SASJedi&lt;/a&gt;&amp;nbsp;Using a bash command to trigger the ksh shell worked, also with the use of X command. I wrote something along the lines of&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;call system ( X 'bash sample.ksh');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and it worked! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am sure the below solution you have posted would also have worked! Thank you again, you have been a great help!&lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 08:06:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Schedule-a-sas-program-to-trigger-a-shell-script/m-p/442267#M110634</guid>
      <dc:creator>visa</dc:creator>
      <dc:date>2018-03-05T08:06:30Z</dc:date>
    </item>
  </channel>
</rss>

