<?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 execute part of code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/316655#M69239</link>
    <description>&lt;P&gt;Write a macro and use conditional statements to execute the parts you want.&lt;/P&gt;
&lt;P&gt;From your description I would have one parameter and pass in the list of models to run.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro run(model_list);
%let model_list=%upcase(model_list);

%if %sysfunc(indexw(&amp;amp;model_list,MODEL1)) %then %do;
* code to run model 1 goes here;
%end;

%if %sysfunc(indexw(&amp;amp;model_list,MODEL2)) %then %do;
* code to run model 2 goes here;
%end;

%* add as many models as you want ;

%mend run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can then call it with 0,1,2,3,.... models by just listing the model names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%run(model1)
%run(model1 model2)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 05 Dec 2016 12:28:17 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2016-12-05T12:28:17Z</dc:date>
    <item>
      <title>how to execute part of code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/316562#M69207</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Please help me on this.&lt;/P&gt;&lt;P&gt;I have a SAS BASE code.This code contains code for 3 models.I want to have a macro variable in beginning which has parameters to set models for which you want to execute for.&lt;/P&gt;&lt;P&gt;for example if a give call like %run(model1,model2)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it executes just part of code related to model1 and model2.&lt;/P&gt;&lt;P&gt;Please guide me how to go about it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Dec 2016 13:49:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/316562#M69207</guid>
      <dc:creator>srdhoble</dc:creator>
      <dc:date>2016-12-04T13:49:48Z</dc:date>
    </item>
    <item>
      <title>Re: how to execute part of code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/316573#M69214</link>
      <description>Hi: This paper has a good introduction to the SAS Macro facility, including an example of conditionally executing code:&lt;BR /&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings13/120-2013.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings13/120-2013.pdf&lt;/A&gt; &lt;BR /&gt;cynthia</description>
      <pubDate>Sun, 04 Dec 2016 17:38:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/316573#M69214</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2016-12-04T17:38:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to execute part of code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/316641#M69230</link>
      <description>&lt;P&gt;You will have to post the code and mark the parts that need to be parameterized, then we can give you hints how to go about it.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 08:31:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/316641#M69230</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-12-05T08:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: how to execute part of code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/316655#M69239</link>
      <description>&lt;P&gt;Write a macro and use conditional statements to execute the parts you want.&lt;/P&gt;
&lt;P&gt;From your description I would have one parameter and pass in the list of models to run.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro run(model_list);
%let model_list=%upcase(model_list);

%if %sysfunc(indexw(&amp;amp;model_list,MODEL1)) %then %do;
* code to run model 1 goes here;
%end;

%if %sysfunc(indexw(&amp;amp;model_list,MODEL2)) %then %do;
* code to run model 2 goes here;
%end;

%* add as many models as you want ;

%mend run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can then call it with 0,1,2,3,.... models by just listing the model names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%run(model1)
%run(model1 model2)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 12:28:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/316655#M69239</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-12-05T12:28:17Z</dc:date>
    </item>
    <item>
      <title>Re: how to execute part of code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/316670#M69243</link>
      <description>&lt;P&gt;Hi,,&lt;/P&gt;&lt;P&gt;&amp;nbsp;Here is my requirement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my script contains code for.&lt;/P&gt;&lt;P&gt;Model1&lt;/P&gt;&lt;P&gt;Model2&lt;/P&gt;&lt;P&gt;Model3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i need a way to run one or more models ast a time..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so my macro calls could be&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%run_model(Model1)&lt;/P&gt;&lt;P&gt;%run(Model1,MOdel2)&lt;/P&gt;&lt;P&gt;%run(Model2,Model3)&lt;/P&gt;&lt;P&gt;%run(Model1,Model2,Model3)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 12:16:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/316670#M69243</guid>
      <dc:creator>srdhoble</dc:creator>
      <dc:date>2016-12-05T12:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: how to execute part of code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/316671#M69244</link>
      <description>&lt;P&gt;Hi,,&lt;/P&gt;&lt;P&gt;&amp;nbsp;Here is my requirement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my script contains code for.&lt;/P&gt;&lt;P&gt;Model1&lt;/P&gt;&lt;P&gt;Model2&lt;/P&gt;&lt;P&gt;Model3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i need a way to run one or more models ast a time..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so my macro calls could be&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%run_model(Model1)&lt;/P&gt;&lt;P&gt;%run(Model1,MOdel2)&lt;/P&gt;&lt;P&gt;%run(Model2,Model3)&lt;/P&gt;&lt;P&gt;%run(Model1,Model2,Model3)&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 12:16:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/316671#M69244</guid>
      <dc:creator>srdhoble</dc:creator>
      <dc:date>2016-12-05T12:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to execute part of code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/316673#M69245</link>
      <description>&lt;P&gt;Don't use commas in the macro call. That implies multiple paramaters. Use spaces so that the list of models is passed as the value to a single parameter.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 12:29:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/316673#M69245</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-12-05T12:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: how to execute part of code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/317302#M69453</link>
      <description>&lt;P&gt;hi,Below is log which is getting generated,the macro call is unable to execute code as %IF condition is comming false.Please Help me on it.Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;options mprint mlogic;&lt;BR /&gt;&amp;nbsp;%runmodels(alpha&amp;nbsp;beta);&lt;BR /&gt;MLOGIC(RUNMODELS): Beginning execution.&lt;BR /&gt;MLOGIC(RUNMODELS): Parameter MODEL_LIST has value alpha beta&lt;BR /&gt;MLOGIC(RUNMODELS): %LET (variable name is MODEL_LIST)&lt;BR /&gt;MLOGIC(RUNMODELS): %IF condition %sysfunc(indexw(&amp;amp;model_list,alpha)) is FALSE&lt;BR /&gt;MLOGIC(RUNMODELS): %IF condition %sysfunc(indexw(&amp;amp;model_list,beta)) is FALSE&lt;BR /&gt;MLOGIC(RUNMODELS): Ending execution.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2016 14:29:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/317302#M69453</guid>
      <dc:creator>srdhoble</dc:creator>
      <dc:date>2016-12-07T14:29:48Z</dc:date>
    </item>
    <item>
      <title>Re: how to execute part of code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/317306#M69456</link>
      <description>&lt;P&gt;Your log messages do not show what value the %LET statement assigned to the MODEL_LIST variable, but if it was like the macro I posted before it would have converted it to upper case to allow the testing to work when users passed in lowercase or mixed case values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the &amp;nbsp;%IF conditions that are resulting in false are checking for lowercase alpha and beta.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Either change the %LET or change the INDEXW() tests.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2016 14:38:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/317306#M69456</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-12-07T14:38:03Z</dc:date>
    </item>
    <item>
      <title>Re: how to execute part of code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/317395#M69489</link>
      <description>&lt;P&gt;Hi I got it working..I have another question related to it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now below is my macro&lt;/P&gt;&lt;P&gt;%macro run(model_list);&lt;/P&gt;&lt;P&gt;%if %sysfunc(indexw(&amp;amp;model_list,ALPHA)) %then %do;&lt;/P&gt;&lt;P&gt;%if %sysfunc(indexw(&amp;amp;model_list,BETA)) %then %do;&lt;/P&gt;&lt;P&gt;--&lt;/P&gt;&lt;P&gt;--&lt;/P&gt;&lt;P&gt;--;&lt;/P&gt;&lt;P&gt;%mend run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and then the macro call&lt;BR /&gt;%run(ALPHA BETA)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so i have to run the macro defination first..scroll down the entire script and then call macro..&lt;/P&gt;&lt;P&gt;is there somewhy i can do both these steps of running macro defination and call in one step?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TIA. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2016 17:28:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/317395#M69489</guid>
      <dc:creator>srdhoble</dc:creator>
      <dc:date>2016-12-07T17:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to execute part of code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/317440#M69508</link>
      <description>&lt;P&gt;SO basically is there a way i can run macro defination and macro call together.?&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2016 21:10:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/317440#M69508</guid>
      <dc:creator>srdhoble</dc:creator>
      <dc:date>2016-12-07T21:10:37Z</dc:date>
    </item>
    <item>
      <title>Re: how to execute part of code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/317443#M69509</link>
      <description>&lt;P&gt;I don't understand the question. &amp;nbsp;If you have a program file then just run the program.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro run(list);
....
%mend run;;
%run(alpha);
%run(beta);

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to maintain the macro defintion and the program that use it as two different source files&amp;nbsp;then just add a %INCLUDE to include the macro definition when needed. &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%include 'run.sas' ;
%run(apha);
%run(beta);

... .more code ...
%run(beta alpha);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that once the macro is compiled you do not need to re-run the definition unless you restart SAS or delete the compiled version somehow. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also look into creating your own autocall library. With AUTOCALL SAS will load the macro definition the first time you try to run it so you don't have to add %include statements for every macro you want to call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2016 21:23:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-execute-part-of-code/m-p/317443#M69509</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-12-07T21:23:41Z</dc:date>
    </item>
  </channel>
</rss>

