<?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 Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484107#M125626</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro rrjow(x,branchP);

PROC SQL;
	create table tbl_&amp;amp;x.  as
	select  *
	from  input_data 
	where branchP=&amp;amp;branchP.
;
QUIT;
%rrjow(x=1, branchP=100);
%rrjow(x=2, branchP=200);
%rrjow(x=3,branchP=300);
%rrjow(x=4,branchP=400);
%rrjow(x=5,branchP=500);&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%rrjow(x=6,branchP=ALL);/*How can I run it???????*/&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to run same piece of code again and again for different branches.&lt;/P&gt;&lt;P&gt;I know that for&amp;nbsp;this situation the best is to use Macro.(It is saving code and save time).&lt;/P&gt;&lt;P&gt;Let's say that I want to run it for following branches: &amp;nbsp;100,200,300,400,500&lt;/P&gt;&lt;P&gt;and also I want to run it for all branches (list of 1000 branches).&lt;/P&gt;&lt;P&gt;My only question is how can I run the macro &amp;nbsp;for all branches ???&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;&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>Sun, 05 Aug 2018 07:42:45 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2018-08-05T07:42:45Z</dc:date>
    <item>
      <title>Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484107#M125626</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro rrjow(x,branchP);

PROC SQL;
	create table tbl_&amp;amp;x.  as
	select  *
	from  input_data 
	where branchP=&amp;amp;branchP.
;
QUIT;
%rrjow(x=1, branchP=100);
%rrjow(x=2, branchP=200);
%rrjow(x=3,branchP=300);
%rrjow(x=4,branchP=400);
%rrjow(x=5,branchP=500);&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%rrjow(x=6,branchP=ALL);/*How can I run it???????*/&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to run same piece of code again and again for different branches.&lt;/P&gt;&lt;P&gt;I know that for&amp;nbsp;this situation the best is to use Macro.(It is saving code and save time).&lt;/P&gt;&lt;P&gt;Let's say that I want to run it for following branches: &amp;nbsp;100,200,300,400,500&lt;/P&gt;&lt;P&gt;and also I want to run it for all branches (list of 1000 branches).&lt;/P&gt;&lt;P&gt;My only question is how can I run the macro &amp;nbsp;for all branches ???&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;&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>Sun, 05 Aug 2018 07:42:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484107#M125626</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-08-05T07:42:45Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484109#M125627</link>
      <description>&lt;P&gt;Put your values into a dataset and use call execute() in a data _null_ step run from that dataset.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 07:51:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484109#M125627</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-05T07:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484110#M125628</link>
      <description>&lt;P&gt;Hello and thank you very much.&lt;/P&gt;&lt;P&gt;I am sorry but I &amp;nbsp;didn't understand.&lt;/P&gt;&lt;P&gt;I need to run also for all branches together....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 08:00:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484110#M125628</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-08-05T08:00:14Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484112#M125629</link>
      <description>&lt;P&gt;May you please send an example&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you so much&lt;/P&gt;&lt;P&gt;Joe&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 08:14:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484112#M125629</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-08-05T08:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484113#M125630</link>
      <description>&lt;P&gt;First, your code won't work because you define your parameters as positional, yet call the macro with keyword parameters. Your calls should look like:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%rrjow (x, branchP)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note the absence of the semicolon after the macro call - it's not needed. Second, it won't work because you have no %MEND statement.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Third, instead of calling the macro thus defined a bunch of times, you should make the second parm accept a list of values and make a provision in the macro code for SQL to handle it. For example:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro rrjow (x=, branchP=) ;  
  proc sql ;                   
    create table tbl_&amp;amp;x as     
    select *                   
    from   input_data          
    where  branchP in (&amp;amp;ranchP)
    ;                          
  quit ;                       
%mend ;                        &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So, if you want to call the macro for a single branch, you'd code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%rrjow (x=5, branchP=500)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Or, if you want a bunch of branches:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%rrjow (x=6, branchP=100 200 300 400 500 600 700 800 900 1000)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;There're other variants that may simplify calling the macro - for example, if you always use a range of branches and they're always multiple of 100, you can parameterize the first and last elements of the range and use the BETWEEN clause instead. But your inquiry isn't specific enough to go beyond what I've offered.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HTH&lt;/P&gt;&lt;P&gt;Paul D&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 09:20:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484113#M125630</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2018-08-05T09:20:50Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484114#M125631</link>
      <description>&lt;P&gt;Oh , you want all those branches in one dataset. You don't need the macro for that, it's a simple join:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table tbl_all as
select a.*
from input_data a
right join control b
on a.branchP = b.branchP
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;where control is a dataset that contains all your wanted branches.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 08:51:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484114#M125631</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-05T08:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484117#M125633</link>
      <description>&lt;P&gt;What&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;is saying is store your parameters in a SAS file and use that control data set to generate the code you need using the CALL EXECUTE routine. This is absolutely how I would approach it in principle much rather than using the macro language (except that instead of using CALL EXECUTE I'd use a different method of generating code - but that's a matter of personal preference).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As a method of generating dynamic code, macros are grossly abused (especially in the clinical trials business), and in a number of ways (for example, from the standpoint of change control) they are vastly inferior to methods based on table-driven approaches. In time, you'll understand subtleties of this nature.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Paul D.&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 08:51:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484117#M125633</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2018-08-05T08:51:02Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484118#M125634</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro rrjow(x,branchP);
%do x=100 %to 1000 %by 100;
PROC SQL;
	create table tbl_&amp;amp;x.  as
	select  *
	from  input_data 
	where branchP=&amp;amp;x.
;
QUIT;
%end;
%mend rrjow;
%rrjow;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 08:52:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484118#M125634</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-08-05T08:52:11Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484120#M125636</link>
      <description>&lt;P&gt;When rereading this post I found a nice formulation for this kind of misunderstanding:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;You never &lt;/STRONG&gt;&lt;STRONG&gt;&lt;EM&gt;solve&lt;/EM&gt; &lt;/STRONG&gt;&lt;STRONG&gt;something with a macro, you can only &lt;/STRONG&gt;&lt;STRONG&gt;&lt;EM&gt;improve&lt;/EM&gt;&lt;/STRONG&gt;&lt;STRONG&gt; an existing solution.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another expression of Maxim 11.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 08:56:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484120#M125636</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-05T08:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484125#M125641</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nicely put.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Furthermore, the very possibility of improving an existing solution with a macro depends on the structure of the solution.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have nothing against macros per se - they're useful when they're used when and where they need to be used.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But not beyond that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 09:16:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484125#M125641</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2018-08-05T09:16:13Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484132#M125647</link>
      <description>&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macroname"&gt;%rrjow&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;x&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;6&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,branchP=in (Select Branch from &lt;/SPAN&gt;&lt;/CODE&gt;&lt;CODE class="  language-sas"&gt;input_data &lt;/CODE&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;try this.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 11:13:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484132#M125647</guid>
      <dc:creator>akash1088</dc:creator>
      <dc:date>2018-08-05T11:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484184#M125669</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;First, your code won't work because you define your parameters as positional, yet call the macro with keyword parameters. Your calls should look like:&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Paul -&lt;/P&gt;
&lt;P&gt;&amp;nbsp; That is a false statement. You can call positional parameters by name. You just can't call named parameters by position.&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 17:27:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484184#M125669</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-05T17:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484195#M125675</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a true statement - on your part, that is. I may be getting signs of early macrodementia. Sad.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Paul D.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 18:50:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484195#M125675</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2018-08-05T18:50:57Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484525#M125797</link>
      <description>&lt;P&gt;If you really want to use a key value like ALL:&lt;/P&gt;
&lt;PRE&gt;%macro rrjow(x,branchP);

PROC SQL;
	create table tbl_&amp;amp;x.  as
	select  *
	from  input_data 
   %if &amp;amp;branchP ne ALL %then %do;
	where branchP=&amp;amp;branchP.
   %end;
;
QUIT;
%mend;&lt;/PRE&gt;
&lt;P&gt;Make sure you pass the parameter value ASS&amp;nbsp;as UPPERCASE or make the macro do that (though if you have character branch values that have lower case letters than gets a little bit trickier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do pay attention to where the semicolons go. The macro conditionals need them the end their statements. The WHERE clause in the SQL does not want the semicolon in between the %if/%end as then you would hit the QUIT instruction without ending the create table first.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2018 20:24:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/484525#M125797</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-06T20:24:50Z</dc:date>
    </item>
  </channel>
</rss>

