<?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: Including a program within itself in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Including-a-program-within-itself/m-p/116958#M24137</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Wrap it in macro code instead.&lt;/P&gt;&lt;P&gt;Assuming you save the code in another sas program as my_program.sas&lt;/P&gt;&lt;P&gt;%macro my_program (age=my_value);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;***your code***;&lt;/P&gt;&lt;P&gt;proc print data=sashelp.class;&lt;/P&gt;&lt;P&gt;where age=&amp;amp;my_value;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%include my_program.sas; *if its in a separate program file;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%my_program(age=14);&lt;/P&gt;&lt;P&gt;%my_program(age=15);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 05 Nov 2012 15:28:24 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2012-11-05T15:28:24Z</dc:date>
    <item>
      <title>Including a program within itself</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Including-a-program-within-itself/m-p/116957#M24136</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to accomplish the following.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a program, which I want to call itself once. So if the name of my program is test.sas, then I figure I need something in lines of the following:&lt;/P&gt;&lt;P&gt;_________________________&lt;/P&gt;&lt;P&gt;&amp;lt;bulk of program&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do this once:&lt;/P&gt;&lt;P&gt;%include "test.sas";&lt;/P&gt;&lt;P&gt;_________________________&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Through the first run of the program, it should run like it uses to, but through the second run, I want to change a parameter. I imagine that the bulk of the program should contain code similar to:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if &amp;amp;ok %then %do;&lt;/P&gt;&lt;P&gt;change parameters;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I suppose that I would also like the variable &amp;amp;ok to be set to 1, when the program is run for the second time, and before that the parameter should be 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For some reason, my own attempts ended up in infinite loops.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Rasmus Hedegaard.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Nov 2012 15:22:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Including-a-program-within-itself/m-p/116957#M24136</guid>
      <dc:creator>Hedegaard</dc:creator>
      <dc:date>2012-11-05T15:22:35Z</dc:date>
    </item>
    <item>
      <title>Re: Including a program within itself</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Including-a-program-within-itself/m-p/116958#M24137</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Wrap it in macro code instead.&lt;/P&gt;&lt;P&gt;Assuming you save the code in another sas program as my_program.sas&lt;/P&gt;&lt;P&gt;%macro my_program (age=my_value);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;***your code***;&lt;/P&gt;&lt;P&gt;proc print data=sashelp.class;&lt;/P&gt;&lt;P&gt;where age=&amp;amp;my_value;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%include my_program.sas; *if its in a separate program file;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%my_program(age=14);&lt;/P&gt;&lt;P&gt;%my_program(age=15);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Nov 2012 15:28:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Including-a-program-within-itself/m-p/116958#M24137</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2012-11-05T15:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: Including a program within itself</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Including-a-program-within-itself/m-p/116959#M24138</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A __default_attr="7948" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt;: The forum could probably provide a better answer if you describe what you are trying to accomplish in less general terms.&amp;nbsp; That said, I agree with Fareeza, but will guess that you want to include the condition in a %do %while loop in the macro.&amp;nbsp; You just have to insure that you have defined the condition such that it won't run infinitely if the condition is never met.&amp;nbsp; e.g., you can make it an or condition like if some criterion is reached or you have exceeded X iterations.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Nov 2012 16:20:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Including-a-program-within-itself/m-p/116959#M24138</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-11-05T16:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: Including a program within itself</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Including-a-program-within-itself/m-p/116960#M24139</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;%include is &lt;EM&gt;not&lt;/EM&gt; a macro invocation, but rather something like a "compiler directive" in other computer languages. This affects the timing when exactly the source is "included," which is earlier than the timing expected by a macro invocation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway, I agree with Arthur in that there may be a better way to implement what you are trying to do. But, if you insist, then here is something close to what you asked for.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: Consolas, Courier New; font-size: 90%; line-height: 1.1;"&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;/* save this file as c:\temp\test.sas before you submit it */&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;x&lt;/SPAN&gt;&lt;SPAN&gt; cd &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;"c:\temp\"&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style="color: #000080;"&gt;%macro&lt;/STRONG&gt;&lt;SPAN&gt; bulk(ok);&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;%put&lt;/SPAN&gt;&lt;SPAN&gt; this is the &amp;lt;bulk&amp;gt; &amp;amp;=ok;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style="color: #000080;"&gt;%mend&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp; bulk;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style="color: #000080;"&gt;data&lt;/STRONG&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;_null_&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;if&lt;/SPAN&gt;&lt;SPAN&gt; not symexist(&lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;"ok"&lt;/SPAN&gt;&lt;SPAN&gt;) &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;then&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;do&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;call&lt;/SPAN&gt;&lt;SPAN&gt; execute(&lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;'%global ok; %let ok=0;'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;call&lt;/SPAN&gt;&lt;SPAN&gt; execute(&lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;'%bulk(ok=&amp;amp;ok);'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;call&lt;/SPAN&gt;&lt;SPAN&gt; execute(&lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;'%let ok=1;'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;call&lt;/SPAN&gt;&lt;SPAN&gt; execute(&lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;'%include "c:\temp\test.sas";'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;end&lt;/SPAN&gt;&lt;SPAN&gt;; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;else&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;do&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;call&lt;/SPAN&gt;&lt;SPAN&gt; execute(&lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;'%bulk(ok=&amp;amp;ok)'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;call&lt;/SPAN&gt;&lt;SPAN&gt; execute(&lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;'%symdel ok;'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;end&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style="color: #000080;"&gt;run&lt;/STRONG&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;/* on log -- some notes removed&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt;&amp;nbsp; this is the &amp;lt;bulk&amp;gt; OK=0&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt;&amp;nbsp; ...&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt;&amp;nbsp; this is the &amp;lt;bulk&amp;gt; OK=1&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt;&amp;nbsp; */&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Nov 2012 16:45:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Including-a-program-within-itself/m-p/116960#M24139</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2012-11-09T16:45:02Z</dc:date>
    </item>
  </channel>
</rss>

