<?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: using rsubmit in a loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693209#M211338</link>
    <description>&lt;P&gt;Sorry, didn't read the documentation carefully enough, thought the WAITFOR syntax was similar to the one used with SASTASK (submitting a SAS session on the same computer). It seems you have to specify the names of the sessions you want to wait for, maybe you can try something like this at the end of your macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;waitfor _ALL_ %do i = 1 %to &amp;amp;n; session&amp;amp;i %end;;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 21 Oct 2020 14:55:41 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2020-10-21T14:55:41Z</dc:date>
    <item>
      <title>using rsubmit in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693112#M211299</link>
      <description>&lt;P&gt;I am trying to create a macro loop that will loop through a table and run a rsubmit on a series of sas-programs. I am trying to emulate how the fork transformation works in DI-studio, but with a dynamic setup that allows me to run any number of sas programs in each remote submit\fork. My control table has one line for each sas program with a file path that is run using %incude.&amp;nbsp; This is my code in progress:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro runABT();
proc sql noprint;
select max(row) into :n from controltable;
quit;

%do i = 1 %to &amp;amp;n.;
	%put session = session&amp;amp;i.;

	proc sql noprint;
	select sascode into :sascode from controltable where row = &amp;amp;i.;
	quit;

	signon session&amp;amp;i. sascmd="!sascmd -nosyntaxcheck -noterminal"  ;
	%syslput sascode=&amp;amp;sascode.;
	rsubmit session&amp;amp;i. wait=no;
	%put sascode= &amp;amp;sascode;
		%include "&amp;amp;sascode.";
	endrsubmit; 
	signoff session&amp;amp;i.; 
%end;
%mend runABT;
%runABT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But with this approach, the second session does not seems to start until the first is finished. Is there a way to have the loop start the second session before the first is finished?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 11:48:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693112#M211299</guid>
      <dc:creator>Ullsokk</dc:creator>
      <dc:date>2020-10-21T11:48:16Z</dc:date>
    </item>
    <item>
      <title>Re: using rsubmit in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693139#M211313</link>
      <description>&lt;P&gt;Your can put a WAIT=NO option on the SIGNON or the RSUBMIT statements. That way, your local session will not wait for the remote sessions to end. If you want to have your macro wait until all your parallel processes are done after submitting them, you can put a WAITFOR _ALL_; statement at the end of the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See&amp;nbsp;the documentation here:&amp;nbsp;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=connref&amp;amp;docsetTarget=n08d4h35p7cygvn1wkicvremmi3d.htm&amp;amp;locale=en" target="_self"&gt;WAITFOR&lt;/A&gt;&amp;nbsp;, &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=connref&amp;amp;docsetTarget=p1eyablk3vvdlkn1h5euyczvt585.htm&amp;amp;locale=en" target="_self"&gt;RSUBMIT&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 12:50:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693139#M211313</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-10-21T12:50:46Z</dc:date>
    </item>
    <item>
      <title>Re: using rsubmit in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693174#M211326</link>
      <description>I have wait=no on the rsubmit, I thought that would do the trick, however, it doesn't behave as I expected. Will try out the waitfor _all_. Will try out putting a wait=no on the signon as well.</description>
      <pubDate>Wed, 21 Oct 2020 13:32:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693174#M211326</guid>
      <dc:creator>Ullsokk</dc:creator>
      <dc:date>2020-10-21T13:32:43Z</dc:date>
    </item>
    <item>
      <title>Re: using rsubmit in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693177#M211328</link>
      <description>I tried wait=no after the signon. But the macro doesn't end, even though both jobs are finished (checked the output tables). Maybe I can't signoff the session untill the waitfor = _all_ has resolved?</description>
      <pubDate>Wed, 21 Oct 2020 13:38:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693177#M211328</guid>
      <dc:creator>Ullsokk</dc:creator>
      <dc:date>2020-10-21T13:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: using rsubmit in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693209#M211338</link>
      <description>&lt;P&gt;Sorry, didn't read the documentation carefully enough, thought the WAITFOR syntax was similar to the one used with SASTASK (submitting a SAS session on the same computer). It seems you have to specify the names of the sessions you want to wait for, maybe you can try something like this at the end of your macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;waitfor _ALL_ %do i = 1 %to &amp;amp;n; session&amp;amp;i %end;;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Oct 2020 14:55:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693209#M211338</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-10-21T14:55:41Z</dc:date>
    </item>
    <item>
      <title>Re: using rsubmit in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693223#M211345</link>
      <description>&lt;P&gt;Try it without the loop first.&amp;nbsp; Then you will know how to code the loop.&lt;/P&gt;
&lt;P&gt;Skip the dynamic definition of SASCODE also.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;signon session1 ....;
%syslput sascode=row1 / remote=session1;
rsubmit session1 wait=no;
%include("&amp;amp;sascode");
endrsumbit;
signon session2 ....;
%syslput sascode=row2 / remote=session2;
rsubmit session2 wait=no;
%include("&amp;amp;sascode");
endrsubmit;
waitfor _all_ session1 session2;
signoff session1;
signoff session2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Oct 2020 15:28:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693223#M211345</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-10-21T15:28:45Z</dc:date>
    </item>
    <item>
      <title>Re: using rsubmit in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693293#M211359</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/68234"&gt;@Ullsokk&lt;/a&gt;&amp;nbsp;- In my experience, having remote SAS sessions and RSUBMITs inside a macro can result in unexpected behaviour. The reason is the remote sessions are not aware they are running inside a macro in a parent SAS session.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;has suggested, get your processing working in open code first. Then perhaps consider a different approach for the looping. I've used CALL EXECUTE successfully for this.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 19:50:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693293#M211359</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-10-21T19:50:52Z</dc:date>
    </item>
    <item>
      <title>Re: using rsubmit in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693359#M211388</link>
      <description>&lt;P&gt;I'd signon before the main loop. Something like.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;%macro runABT();
%local i n;
proc sql noprint;
  select max(ROW) into :n from CONTROLTABLE;
  select SASCODE into :saspgm1-:saspgm999 from CONTROLTABLE;
quit;
%do i = 1 %to &amp;amp;n.;
  signon session&amp;amp;i. sascmd="!sascmd -nosyntaxcheck -noterminal"  ;
  %syslput sascode=&amp;amp;&amp;amp;saspgm&amp;amp;i / remote=session&amp;amp;i.;
%end;
%do i = 1 %to &amp;amp;n.;
  rsubmit session&amp;amp;i. wait=no;
    %put pgm=&amp;amp;&amp;amp;saspgm&amp;amp;i;
    %include "&amp;amp;&amp;amp;saspgm&amp;amp;i";
  endrsubmit; 
%end;
%do i = 1 %to &amp;amp;n.;
  signoff session&amp;amp;i.; 
%end;
%mend runABT;
%runABT;&lt;/LI-CODE&gt;
&lt;P&gt;to ensure the signon/off steps don't spoil the waiting.&lt;/P&gt;
&lt;P&gt;Add&amp;nbsp;&amp;nbsp;&lt;FONT face="courier new,courier"&gt;waitfor _all_&lt;/FONT&gt; next.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2020 01:26:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693359#M211388</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-10-22T01:26:09Z</dc:date>
    </item>
    <item>
      <title>Re: using rsubmit in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693362#M211390</link>
      <description>&lt;P&gt;Oops, just saw I got my remote macro variable name confused. Please correct accordingly.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2020 01:42:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693362#M211390</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-10-22T01:42:38Z</dc:date>
    </item>
    <item>
      <title>Re: using rsubmit in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693370#M211394</link>
      <description>&lt;P&gt;I've only skimmed your post, so I may misunderstand what you're trying to do.&amp;nbsp; And I can't tell if you're using rsubmit to submit code on a remote server, or the current one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, have a look at&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/RunAll.sas" target="_blank"&gt;https://github.com/scottbass/SAS/blob/master/Macro/RunAll.sas&lt;/A&gt;&amp;nbsp;and&amp;nbsp;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/RunAll_ControlTable.sas" target="_blank"&gt;https://github.com/scottbass/SAS/blob/master/Macro/RunAll_ControlTable.sas&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps they will help with what you're trying to do?&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2020 02:34:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693370#M211394</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2020-10-22T02:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: using rsubmit in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693404#M211412</link>
      <description>&lt;P&gt;Thanks, that looks really interesting. I am running code om the current server. I basically want all programs to run at the same time, in different sessions.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2020 06:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693404#M211412</guid>
      <dc:creator>Ullsokk</dc:creator>
      <dc:date>2020-10-22T06:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: using rsubmit in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693423#M211423</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/68234"&gt;@Ullsokk&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks, that looks really interesting. I am running code om the current server. I basically want all programs to run at the same time, in different sessions.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;My code runs SAS in batch mode, i.e. sas.exe -sysin myprogram.sas.&amp;nbsp; It uses the first SAS session as the "scripting engine" to launch multiple SAS sessions, and abort if upstream dependencies fail.&amp;nbsp; When I used it I had SAS DMS on the laptop, so the scripting engine ran in interactive mode, but the remaining sessions ran in batch.&amp;nbsp; As much as you can get batch on windows - there were a bunch of icons in the taskbar.&amp;nbsp; They don't run in "true" background as you can get with *nix.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you just want to run all programs at once, either modify the macro or simply set all programs to the same "level", i.e. all "1".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that more is not necessarily better; when I ran this on (an old) two core CPU laptop, running more than two programs at a time increased the total execution run time for all the programs.&amp;nbsp; YMMV.&amp;nbsp; So you may want to experiment with the max_threads setting.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2020 08:14:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-rsubmit-in-a-loop/m-p/693423#M211423</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2020-10-22T08:14:22Z</dc:date>
    </item>
  </channel>
</rss>

