<?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 Schedule SAS Job after table is avaliable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Schedule-SAS-Job-after-table-is-avaliable/m-p/352455#M82157</link>
    <description>&lt;P&gt;Hi SAS Users,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table in Oracle which gets updated daily manually. I want to pull some data from that table after it was updated&amp;nbsp;and want to schedule this process. I can't schedule a job when ever I wish. I can put my code in a folder that was setup for scheduling the jobs. If I place my program.sas file in that folder the job will be scheduled based on queue in folder at 12.01 AM every day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can get the timestamp when the table was refreshed using ALL_TAB_MODIFICATIONS table in Oracle.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
connect to odbc as mycon
   (datasrc=ABCDEF user=surya password=xxxxxx);

select Timestamp INTO: Timestamp
   from connection to mycon
      (select * from ALL_TAB_modifications
		Where Table_owner='ORCL' and Table_name='TABLE_ORACLE';);

disconnect from mycon;
quit;

%put &amp;amp;Timestamp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;My program to schedule is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
connect to odbc as mycon
   (datasrc=ABCDEF user=surya password=xxxxxx);
Create table test1 as
select *
   from connection to mycon
      (select * from ORCL.TABLE_ORACLE
  where Name = 'SURYA');

disconnect from mycon;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm looking code for something like, if my program starts running at 12.01 AM it has to sleep untill 9:00 am and from then it has to look for the table avaliability every one hour. i.e at 9:00 AM it has to check for table avaliability if avaliable then run my query and stop loop or sleep for 1 hour and again check at 10:00AM if avaliable run the query and stop loop or sleep for 1 hour........untill 5:00PM. Finally if the update of table is not found untill 5 pm then stop process and repeat next day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in Advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 22 Apr 2017 17:34:05 GMT</pubDate>
    <dc:creator>SuryaKiran</dc:creator>
    <dc:date>2017-04-22T17:34:05Z</dc:date>
    <item>
      <title>Schedule SAS Job after table is avaliable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Schedule-SAS-Job-after-table-is-avaliable/m-p/352455#M82157</link>
      <description>&lt;P&gt;Hi SAS Users,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table in Oracle which gets updated daily manually. I want to pull some data from that table after it was updated&amp;nbsp;and want to schedule this process. I can't schedule a job when ever I wish. I can put my code in a folder that was setup for scheduling the jobs. If I place my program.sas file in that folder the job will be scheduled based on queue in folder at 12.01 AM every day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can get the timestamp when the table was refreshed using ALL_TAB_MODIFICATIONS table in Oracle.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
connect to odbc as mycon
   (datasrc=ABCDEF user=surya password=xxxxxx);

select Timestamp INTO: Timestamp
   from connection to mycon
      (select * from ALL_TAB_modifications
		Where Table_owner='ORCL' and Table_name='TABLE_ORACLE';);

disconnect from mycon;
quit;

%put &amp;amp;Timestamp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;My program to schedule is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
connect to odbc as mycon
   (datasrc=ABCDEF user=surya password=xxxxxx);
Create table test1 as
select *
   from connection to mycon
      (select * from ORCL.TABLE_ORACLE
  where Name = 'SURYA');

disconnect from mycon;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm looking code for something like, if my program starts running at 12.01 AM it has to sleep untill 9:00 am and from then it has to look for the table avaliability every one hour. i.e at 9:00 AM it has to check for table avaliability if avaliable then run my query and stop loop or sleep for 1 hour and again check at 10:00AM if avaliable run the query and stop loop or sleep for 1 hour........untill 5:00PM. Finally if the update of table is not found untill 5 pm then stop process and repeat next day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in Advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Apr 2017 17:34:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Schedule-SAS-Job-after-table-is-avaliable/m-p/352455#M82157</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2017-04-22T17:34:05Z</dc:date>
    </item>
    <item>
      <title>Re: Schedule SAS Job after table is avaliable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Schedule-SAS-Job-after-table-is-avaliable/m-p/352494#M82180</link>
      <description>This sounds awkward. &lt;BR /&gt;My immediate feeling is that it should be possible  from the Oracle side do some kind of push notice of the modification. &lt;BR /&gt;&lt;BR /&gt;Also, if you are on UNIX/Linux or Windows, you sjoule be able to use crontab/Windows task which let you schedule a job when you want, like the hours you mention. Then there is no need to build a loop. Then your query would either check that the modification time is within the last interval, or you build some logic on the SAS side with a timestamp in log data set.</description>
      <pubDate>Sat, 22 Apr 2017 20:47:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Schedule-SAS-Job-after-table-is-avaliable/m-p/352494#M82180</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-04-22T20:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: Schedule SAS Job after table is avaliable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Schedule-SAS-Job-after-table-is-avaliable/m-p/352500#M82181</link>
      <description>&lt;P&gt;I don't have any other option then doing in this way.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Apr 2017 21:20:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Schedule-SAS-Job-after-table-is-avaliable/m-p/352500#M82181</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2017-04-22T21:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: Schedule SAS Job after table is avaliable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Schedule-SAS-Job-after-table-is-avaliable/m-p/352506#M82182</link>
      <description>&lt;P&gt;Agree with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH&lt;/a&gt;, writing you own scheduler in SAS will be awkward at best.&amp;nbsp; And will waste resources, as your SAS session will be running for 17 hours a day, even though most of that time is sleeping.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That said, there are plenty of user group papers that discuss how to do this sort of scheduling by using the sleep() function (search lexjansen.com).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some approach like below pseudo code should be feasible.&amp;nbsp; Note that on windows sleep(60) is 60 seconds, but on linux it's 60 miliseconds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro doit() ;           
  %local rc done ;

  %let rc=%sysfunc(sleep(60*60*9)) ; *sleep 9 hours (from SAS session start at midnight);&lt;BR /&gt;&lt;BR /&gt;  %let done=0;

  %do until( (&amp;amp;done) or (%sysfunc(time()) &amp;gt; (60*60*17))  ) ;   %*do until done or 1700;
    
    *Run your query ;
    
    %if &amp;lt;some return code from your query is happy&amp;gt; %then %let done=1 ;
    %else %let rc=%sysfunc(sleep(60*60)) ;  %*sleep an hour;

  %end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 23 Apr 2017 11:54:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Schedule-SAS-Job-after-table-is-avaliable/m-p/352506#M82182</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2017-04-23T11:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: Schedule SAS Job after table is avaliable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Schedule-SAS-Job-after-table-is-avaliable/m-p/352523#M82188</link>
      <description>&lt;P&gt;If you are not allowed to schedule jobs yourself, can your SAS administrator do it for you? Using the SAS SLEEP function as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt; has suggested is a great way of delaying your job until the data is available. I do something similar myself, using a macro loop to check if a table has been updated every 15 minutes or another specified interval.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Apr 2017 00:50:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Schedule-SAS-Job-after-table-is-avaliable/m-p/352523#M82188</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2017-04-23T00:50:20Z</dc:date>
    </item>
  </channel>
</rss>

