<?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 run mutliple SAS files in batch mode with single program/ or simple way in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-run-mutliple-SAS-files-in-batch-mode-with-single-program/m-p/775458#M246503</link>
    <description>&lt;P&gt;Change the data step from the macro to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data filesWithCodes;
  base = "&amp;amp;filesLocation.";
  length file $ 256 folderRef fileRef $ 8;

  folderRef = "_%sysfunc(datetime(), hex6.)0";

  rc=filename(folderRef, base);
  folderid=dopen(folderRef);

  N = dnum(folderId);
  j = 0;
  do i=1 to N; drop i;
    file = dread(folderId, i);
    if upcase(scan(file, -1, ".")) = "SAS" then
      do;
        j+1;
        call symputX(cats("TEST_", j), file, "L");
        output; 
      end;
  end;

  rc = dclose(folderid);
  rc = filename(folderRef);

  call symputX("numberOfTests", j, "L");
  stop;
run;
proc print data = filesWithCodes;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Oct 2021 17:53:10 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2021-10-20T17:53:10Z</dc:date>
    <item>
      <title>how to run mutliple SAS files in batch mode with single program/ or simple way</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-run-mutliple-SAS-files-in-batch-mode-with-single-program/m-p/774369#M246112</link>
      <description>&lt;P&gt;I have multiple table programs in a folder that need to be run in batch mode. I am presently running them individually one at a time or with one Programming code where I&amp;nbsp; Included the&amp;nbsp; SAS&amp;nbsp; tables file names&amp;nbsp; that I need with %include and run. I would like to know is there a simple way to run this or automate it? The following image is an example to refer. Any help with this greatly appreciated. If you know any reference material please suggest me. Thanks&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture-1.PNG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64736iAB068FCED5870587/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture-1.PNG" alt="Capture-1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 21:51:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-run-mutliple-SAS-files-in-batch-mode-with-single-program/m-p/774369#M246112</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2021-10-14T21:51:46Z</dc:date>
    </item>
    <item>
      <title>Re: how to run mutliple SAS files in batch mode with single program/ or simple way</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-run-mutliple-SAS-files-in-batch-mode-with-single-program/m-p/774379#M246116</link>
      <description>&lt;P&gt;In a single SAS program you can do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%include "C:\Batchrun\prog1.sas";
%include "C:\Batchrun\prog2.sas";
%include "C:\Batchrun\prog3.sas";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will run programs prog1, prog2 and prog3 in the order specified. You could do a wildcard %INCLUDE (*.sas) but that won't necessarily control the order the programs are run in.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 22:12:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-run-mutliple-SAS-files-in-batch-mode-with-single-program/m-p/774379#M246116</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-10-14T22:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to run mutliple SAS files in batch mode with single program/ or simple way</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-run-mutliple-SAS-files-in-batch-mode-with-single-program/m-p/774383#M246119</link>
      <description>&lt;P&gt;Thanks for the response SASKiwi. I mentioned in my text that, I am presently running with %include only, But it won't create log or lst file for the programs. I also want to create the lst and log files.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 22:54:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-run-mutliple-SAS-files-in-batch-mode-with-single-program/m-p/774383#M246119</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2021-10-14T22:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to run mutliple SAS files in batch mode with single program/ or simple way</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-run-mutliple-SAS-files-in-batch-mode-with-single-program/m-p/774388#M246123</link>
      <description>&lt;P&gt;To do that run SAS from the Windows command line: sas "MyProg.sas". Check this &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/hostwin/p16esisc4nrd5sn1ps5l6u8f79k6.htm#p01fzykn6n0s73n164xasi1t3ii9" target="_blank" rel="noopener"&gt;link&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 23:48:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-run-mutliple-SAS-files-in-batch-mode-with-single-program/m-p/774388#M246123</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-10-14T23:48:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to run mutliple SAS files in batch mode with single program/ or simple way</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-run-mutliple-SAS-files-in-batch-mode-with-single-program/m-p/774395#M246125</link>
      <description>&lt;P&gt;Your question touches on two distinct areas:&lt;/P&gt;
&lt;P&gt;1. How to schedule (automate) processes&lt;/P&gt;
&lt;P&gt;2. How to structure (design) your jobs&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here some links for &lt;STRONG&gt;scheduling&lt;/STRONG&gt; (there is much more out there):&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sgf/2013/08/14/four-ways-to-schedule-sas-tasks/" target="_blank" rel="noopener"&gt;https://blogs.sas.com/content/sgf/2013/08/14/four-ways-to-schedule-sas-tasks/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/doc/en/bicdc/9.4/scheduleug/titlepage.htm" target="_blank" rel="noopener"&gt;https://go.documentation.sas.com/doc/en/bicdc/9.4/scheduleug/titlepage.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;In regards of job design&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;I would NEVER have fully qualified paths in individual jobs. Ideally define your libraries in metadata and/or create some %init macro where you define such paths.&lt;/P&gt;
&lt;P&gt;Normally the folder structure within a "project" is meant to be stable but the path to the project folder can change. Often it's worth to define the root path to the project folder in such an %init_projectA() macro (or even the autoexec); something like %let projectA=&amp;lt;path&amp;gt;.&lt;/P&gt;
&lt;P&gt;Then within your code you still can have a libname or filename like fiilename myfile "&amp;amp;projectA/&amp;lt;foldera&amp;gt;/&amp;lt;folderb&amp;gt;/myfile.txt";&lt;/P&gt;
&lt;P&gt;Make sure that you store the %init_projectA() macro in a folder that's part of the SAS Autocall facility - or add the folder to this facility via extending the SASAUTOS option (in the usermods version of the .cfg or autoexec).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...above written a bit quickly and I'm sure there are good papers and blogs out there if you search a bit.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Oct 2021 00:36:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-run-mutliple-SAS-files-in-batch-mode-with-single-program/m-p/774395#M246125</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-10-15T00:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to run mutliple SAS files in batch mode with single program/ or simple way</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-run-mutliple-SAS-files-in-batch-mode-with-single-program/m-p/774434#M246138</link>
      <description>&lt;P&gt;If your session has the XCMD option on, you could use this macro (read comments inside the macro for details and to adjust it for your task):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro runInParallel(filesLocation);

/* get the list of files */
data filesWithCodes;
  base = "&amp;amp;filesLocation.";
  length file $ 256 folderRef fileRef $ 8;

  folderRef = "_%sysfunc(datetime(), hex6.)0";

  rc=filename(folderRef, base);
  folderid=dopen(folderRef);

  N = dnum(folderId);
  do i=1 to N; drop i;
    file = dread(folderId, i);
    call symputX(cats("TEST_", i), file, "L");
    output; 
  end;

  rc = dclose(folderid);
  rc = filename(folderRef);

  call symputX("numberOfTests", N, "L");
  stop;
run;
proc print data = filesWithCodes;
run;

/* setup sas sessions */
%local SASROOT SASEXE SASWORK;
filename sasroot "!SASROOT";
%let SASROOT=%sysfunc(PATHNAME(sasroot));
filename sasroot;
%put *&amp;amp;SASROOT.*;
%let SASEXE=&amp;amp;SASROOT./sas;
%put *&amp;amp;SASEXE.*;
%let SASWORK=%sysfunc(GETOPTION(work));
%put *&amp;amp;SASWORK.*;

%local t;   
systask kill 
  %do t = 1 %to &amp;amp;numberOfTests.;
    sas&amp;amp;t. 
  %end;
wait;

/* run parallel jobs */
/* you can adjust the config file location yourself by editing `-config ""&amp;amp;SASROOT./sasv9.cfg""` */
/* you can adjust outputs and logs locations yourself */
%do t = 1 %to &amp;amp;numberOfTests.;
%local sasstat&amp;amp;t.;
systask command
"""&amp;amp;SASEXE.""
  -sysin ""&amp;amp;filesLocation./&amp;amp;&amp;amp;TEST_&amp;amp;t.""
  -print ""&amp;amp;filesLocation./&amp;amp;&amp;amp;TEST_&amp;amp;t...lst""
    -log ""&amp;amp;filesLocation./&amp;amp;&amp;amp;TEST_&amp;amp;t...log""
 -config ""&amp;amp;SASROOT./sasv9.cfg""
   -work ""&amp;amp;SASWORK.""
 -noterminal
 -rsasuser"
taskname=sas&amp;amp;t.
status=sasstat&amp;amp;t.
NOWAIT /* change it to WAIT if you dont need to run it in parallel */
;
%end;

waitfor _all_
  %do t = 1 %to &amp;amp;numberOfTests.;
    sas&amp;amp;t. 
  %end;
;

data _null_;
  put "NOTE: The End!";
run;

%mend runInParallel;

options NOQUOTELENMAX;
%runInParallel(C:\Users\bart\Desktop\abc)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Fri, 15 Oct 2021 07:44:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-run-mutliple-SAS-files-in-batch-mode-with-single-program/m-p/774434#M246138</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-10-15T07:44:25Z</dc:date>
    </item>
    <item>
      <title>Re: how to run mutliple SAS files in batch mode with single program/ or simple way</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-run-mutliple-SAS-files-in-batch-mode-with-single-program/m-p/775393#M246477</link>
      <description>&lt;P&gt;&amp;nbsp;Thank you so much . I tried this macro, It covers 80% or my requirement. However, there was an issue for me. This macro running all the files in batch mode even though they are not . SAS files. In my case its running the PNG, and even folders&amp;nbsp; and creating the log file. I am not familiar with the system options, I tried controlling the&amp;nbsp; SAS files but its not working.&amp;nbsp; do you have any idea how to modify it to run only SAS files!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Oct 2021 13:07:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-run-mutliple-SAS-files-in-batch-mode-with-single-program/m-p/775393#M246477</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2021-10-20T13:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: how to run mutliple SAS files in batch mode with single program/ or simple way</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-run-mutliple-SAS-files-in-batch-mode-with-single-program/m-p/775458#M246503</link>
      <description>&lt;P&gt;Change the data step from the macro to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data filesWithCodes;
  base = "&amp;amp;filesLocation.";
  length file $ 256 folderRef fileRef $ 8;

  folderRef = "_%sysfunc(datetime(), hex6.)0";

  rc=filename(folderRef, base);
  folderid=dopen(folderRef);

  N = dnum(folderId);
  j = 0;
  do i=1 to N; drop i;
    file = dread(folderId, i);
    if upcase(scan(file, -1, ".")) = "SAS" then
      do;
        j+1;
        call symputX(cats("TEST_", j), file, "L");
        output; 
      end;
  end;

  rc = dclose(folderid);
  rc = filename(folderRef);

  call symputX("numberOfTests", j, "L");
  stop;
run;
proc print data = filesWithCodes;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Oct 2021 17:53:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-run-mutliple-SAS-files-in-batch-mode-with-single-program/m-p/775458#M246503</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-10-20T17:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: how to run mutliple SAS files in batch mode with single program/ or simple way</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-run-mutliple-SAS-files-in-batch-mode-with-single-program/m-p/775726#M246596</link>
      <description>&lt;P&gt;Perfect. It worked , Thanks. &lt;span class="lia-unicode-emoji" title=":hugging_face:"&gt;🤗&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Oct 2021 18:14:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-run-mutliple-SAS-files-in-batch-mode-with-single-program/m-p/775726#M246596</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2021-10-21T18:14:34Z</dc:date>
    </item>
  </channel>
</rss>

