<?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: Smart way to add code in all programs in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588436#M168175</link>
    <description>&lt;P&gt;At one point, your scheduler has to run SAS. Most likely this is done by running a shell script like sasbatch.sh which is found in the SASApp/BatchServer directory of your BI server configuration. Find that script (your StoneBranch admins can help you in that), make a copy of it, expand that copy so that a small SAS program which records information is run before and after the main call, and use that copy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;We're executing the program via scheduling tool called Stone Branch. So you&lt;BR /&gt;are suggesting me to add and call my program which I want to add in after&lt;BR /&gt;the completion of each program?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 13 Sep 2019 06:03:37 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-09-13T06:03:37Z</dc:date>
    <item>
      <title>Smart way to add code in all programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588416#M168160</link>
      <description>I want to add few steps at the end of all programs which is located in particular folder. One way to do this is adding INCLUDE statement in all the programs.&lt;BR /&gt;&lt;BR /&gt;But I don't want to touch all the programs to do this task as there are 200+ program. Is there any other way to achieve this objective without touching all the programs? &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 13 Sep 2019 01:53:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588416#M168160</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-09-13T01:53:32Z</dc:date>
    </item>
    <item>
      <title>Re: Smart way to add code in all programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588419#M168161</link>
      <description>&lt;P&gt;One way would be to create a controlling SAS program whose job is to run any of your 200 plus programs using a %INCLUDE, then does the extra steps following it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could even pass a parameter into this controlling program which specifies which of your programs to run so you don't need to keep changing it all the time. This functionality is particularly useful when running your programs in batch mode.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2019 02:12:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588419#M168161</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-09-13T02:12:21Z</dc:date>
    </item>
    <item>
      <title>Re: Smart way to add code in all programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588426#M168166</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming this is still about writing job status information to some table and that you will be running your code in batch:&lt;/P&gt;
&lt;P&gt;I've faced in the past a similar challenge where I had to add such processing at the beginning and the end of each job after everything had already been built and unit tested. The approach I've taken there:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Create an autocall macro for writing the status information&lt;/P&gt;
&lt;P&gt;2. Add the call to this autocall macro via system options -initstmt and -termstmt as part of the batch string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This approach allowed me to implement such loggin without having to touch the DIS jobs.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2019 03:26:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588426#M168166</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-09-13T03:26:54Z</dc:date>
    </item>
    <item>
      <title>Re: Smart way to add code in all programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588429#M168169</link>
      <description>Could you please point me to the document to implement the approach which&lt;BR /&gt;you suggested?&lt;BR /&gt;</description>
      <pubDate>Fri, 13 Sep 2019 03:37:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588429#M168169</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-09-13T03:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: Smart way to add code in all programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588432#M168172</link>
      <description>May I request you to guide me with one small example?&lt;BR /&gt;</description>
      <pubDate>Fri, 13 Sep 2019 04:09:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588432#M168172</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-09-13T04:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: Smart way to add code in all programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588433#M168173</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I want to add few steps at the end of all programs which is located in particular folder. One way to do this is adding INCLUDE statement in all the programs.&lt;BR /&gt;&lt;BR /&gt;But I don't want to touch all the programs to do this task as there are 200+ program. Is there any other way to achieve this objective without touching all the programs? &lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do it in the script that runs the programs. That way you do not have to touch any existing SAS codes.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2019 05:35:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588433#M168173</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-09-13T05:35:33Z</dc:date>
    </item>
    <item>
      <title>Re: Smart way to add code in all programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588434#M168174</link>
      <description>We're executing the program via scheduling tool called Stone Branch. So you&lt;BR /&gt;are suggesting me to add and  call my program which I want to add in after&lt;BR /&gt;the completion of each program?&lt;BR /&gt;</description>
      <pubDate>Fri, 13 Sep 2019 05:42:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588434#M168174</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-09-13T05:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: Smart way to add code in all programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588436#M168175</link>
      <description>&lt;P&gt;At one point, your scheduler has to run SAS. Most likely this is done by running a shell script like sasbatch.sh which is found in the SASApp/BatchServer directory of your BI server configuration. Find that script (your StoneBranch admins can help you in that), make a copy of it, expand that copy so that a small SAS program which records information is run before and after the main call, and use that copy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;We're executing the program via scheduling tool called Stone Branch. So you&lt;BR /&gt;are suggesting me to add and call my program which I want to add in after&lt;BR /&gt;the completion of each program?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2019 06:03:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588436#M168175</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-09-13T06:03:37Z</dc:date>
    </item>
    <item>
      <title>Re: Smart way to add code in all programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588437#M168176</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;We're executing the program via scheduling tool called Stone Branch. So you&lt;BR /&gt;are suggesting me to add and call my program which I want to add in after&lt;BR /&gt;the completion of each program?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The scheduler will call SAS programs issuing a command like:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;.../sasbatch.sh -sysin &amp;lt;.../your sas program.sas&amp;gt;&amp;nbsp; .....&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So here you can add the options -initstmt and -termstmt&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I.e. if you want to execute your login macro right after the DIS code (passed in via -sysin) then it would be something like&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;.../sasbatch.sh -sysin &amp;lt;.../your sas program.sas&amp;gt;&amp;nbsp; .....-termstmt '%mymacro()'&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro itself will execute in the same session and though you can use in this macro any of the DIS generated global macro variables.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2019 06:05:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588437#M168176</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-09-13T06:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: Smart way to add code in all programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588438#M168177</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;proposes is also a viable approach and something I've done successfully in the past.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;....or you can also as a combination of both approaches add the -....stmt options to your copy of the sasbatch.sh - or eventually even better to a copy of sasbatch_usermods.sh&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2019 06:09:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588438#M168177</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-09-13T06:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: Smart way to add code in all programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588512#M168208</link>
      <description>&lt;P&gt;I don't understand this part &lt;EM&gt;'you can also as a combination of both approaches add the -....stmt options to your copy of the sasbatch.sh - or eventually even better to a copy of sasbatch_usermods.sh'&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2019 13:27:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588512#M168208</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-09-13T13:27:33Z</dc:date>
    </item>
    <item>
      <title>Re: Smart way to add code in all programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588690#M168279</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp; - the controlling program approach is really very simple:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%include "&amp;lt;MySASProgram.sas&amp;gt;"; * Put your program name here;

* Now add the code you want to run afterwards for each of your programs here;

&amp;lt;Common program code&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you could enhance it using SYSPARM: &lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n1ug7uhp2d4vpmn149431l4pcucf.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n1ug7uhp2d4vpmn149431l4pcucf.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Start SAS like so: sas MyControlProgram.sas -sysparm = "&lt;CODE class=" language-sas"&gt;MySASProgram"&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null;
  * This reads the value of sysparm;
  MyProgramName = sysparm(); 

  * This creates a %include statement then runs it;
  call execute('%include "' !! strip(MyProgramName) !! '.sas";');
run;
  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;Note, change the sysparm to change the program you want to run. The above program does not change at all.&lt;/P&gt;</description>
      <pubDate>Sat, 14 Sep 2019 02:10:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588690#M168279</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-09-14T02:10:46Z</dc:date>
    </item>
    <item>
      <title>Re: Smart way to add code in all programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588693#M168281</link>
      <description>Well, assume SAS programs which I have in the folder is program1.sas,&lt;BR /&gt;program2.sas and program3.sas.&lt;BR /&gt;&lt;BR /&gt;And the common program which I want to execute at the end of each program&lt;BR /&gt;is common_program.sas.&lt;BR /&gt;&lt;BR /&gt;Then how will you fit these program(s) in your proposed solution?&lt;BR /&gt;</description>
      <pubDate>Sat, 14 Sep 2019 02:30:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588693#M168281</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-09-14T02:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: Smart way to add code in all programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588705#M168287</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I don't understand this part &lt;EM&gt;'you can also as a combination of both approaches add the -....stmt options to your copy of the sasbatch.sh - or eventually even better to a copy of sasbatch_usermods.sh'&lt;/EM&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;sasbatch.sh is just a shell script which takes input parameters and constructs a batch command line which it then executes. Because it's just a shell script you can amend it to do whatever else you need. If you look into the script then - if I remember right - there is already logic built which adds some of the required options if they haven't been passed in as parameters. You could extend this logic and also add -initstmt and -termstmt in the same manner.&lt;/P&gt;
&lt;P&gt;The script is cascaded in the same way the config files and autoexecs are.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Sep 2019 07:50:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Smart-way-to-add-code-in-all-programs/m-p/588705#M168287</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-09-14T07:50:42Z</dc:date>
    </item>
  </channel>
</rss>

