<?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 Defaut argument for Macro statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Defaut-argument-for-Macro-statement/m-p/558293#M155801</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a test macro, as shown:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro test (rule = "");&lt;/P&gt;&lt;P&gt;&amp;nbsp; %if &amp;amp;rule. = "" %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Data Example;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; set Source;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MEND test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to have rule set to ¨¨ as its default value, but if I give an argument to the macro, I want it to use that value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But if i try %test(); or %test; or even %test("value"); they don't run. Is it possible to have default values for arguments?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Mon, 13 May 2019 13:24:15 GMT</pubDate>
    <dc:creator>rodrigobarg</dc:creator>
    <dc:date>2019-05-13T13:24:15Z</dc:date>
    <item>
      <title>Defaut argument for Macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Defaut-argument-for-Macro-statement/m-p/558293#M155801</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a test macro, as shown:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro test (rule = "");&lt;/P&gt;&lt;P&gt;&amp;nbsp; %if &amp;amp;rule. = "" %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Data Example;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; set Source;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MEND test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to have rule set to ¨¨ as its default value, but if I give an argument to the macro, I want it to use that value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But if i try %test(); or %test; or even %test("value"); they don't run. Is it possible to have default values for arguments?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2019 13:24:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Defaut-argument-for-Macro-statement/m-p/558293#M155801</guid>
      <dc:creator>rodrigobarg</dc:creator>
      <dc:date>2019-05-13T13:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: Defaut argument for Macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Defaut-argument-for-Macro-statement/m-p/558295#M155802</link>
      <description>&lt;P&gt;Seems to execute for me. By the way, you ought not use quotes or double-quotes to enclose the values of your macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test (rule = );
  %put &amp;amp;=rule;
  %if &amp;amp;rule. =  %then %do;
      Data Example;
      set Source;
      run;
  %end;
%MEND test;

%test()&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2019 13:31:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Defaut-argument-for-Macro-statement/m-p/558295#M155802</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-13T13:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: Defaut argument for Macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Defaut-argument-for-Macro-statement/m-p/558297#M155804</link>
      <description>&lt;P&gt;Works fine for me? You are missing a semicolon after your %end statement though?&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2019 13:32:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Defaut-argument-for-Macro-statement/m-p/558297#M155804</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-05-13T13:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: Defaut argument for Macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Defaut-argument-for-Macro-statement/m-p/558299#M155805</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;You are missing a semicolon after your %end statement though?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, I caught that too, but forgot to mention it&amp;nbsp;&lt;img id="smileyfrustrated" class="emoticon emoticon-smileyfrustrated" src="https://communities.sas.com/i/smilies/16x16_smiley-frustrated.png" alt="Smiley Frustrated" title="Smiley Frustrated" /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2019 13:35:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Defaut-argument-for-Macro-statement/m-p/558299#M155805</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-13T13:35:18Z</dc:date>
    </item>
    <item>
      <title>Re: Defaut argument for Macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Defaut-argument-for-Macro-statement/m-p/558301#M155807</link>
      <description>&lt;P&gt;If you define the parameter as named (which is required to take advantage of the default value) then you need to call it with the name.&lt;/P&gt;
&lt;P&gt;So your last example call would not work.&lt;/P&gt;
&lt;P&gt;Examples of call that would work with your macro definition.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%test;
%test()
%test(rule=some other value)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Otherwise add your own code for default values into the body of the macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(rule);
%if %length(&amp;amp;rule)=0 %then %let rule=Default value;
....
%mend test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can pass the value of RULE by position.&amp;nbsp; Note that you can still call it with the name if you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%test;
%test()
%test(some other value)
%test(rule=some other value)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 May 2019 15:01:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Defaut-argument-for-Macro-statement/m-p/558301#M155807</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-13T15:01:30Z</dc:date>
    </item>
  </channel>
</rss>

