<?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: Retrieve Macro Parameter Default Value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retrieve-Macro-Parameter-Default-Value/m-p/827465#M326866</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184742"&gt;@xxformat_com&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was wondering if there is a way to retrieve the default value of a macro parameter in a macro variable or so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro demo (lib=work);
%if &amp;amp;lib.= %str( ) %then 
    %do;
        %let &amp;amp;lib. = &amp;lt;default macro parameter value&amp;gt;;
    %end;
%mend demo;
%demo(lib=);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Just put the default into one place. Move it from the %MACRO statement into your %IF/%THEN logic.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro demo (lib=);
%if 0=%length(&amp;amp;lib) %then %let lib=WORK ;
%put &amp;amp;=lib ;
%mend demo;
%demo(lib=);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also it is much easier to test for empty values by actually testing if the value is empty. By using %LENGTH().&amp;nbsp; If someone goes to the work of using macro quoting so they could pass in a space character that is not an empty value.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 06 Aug 2022 14:21:54 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-08-06T14:21:54Z</dc:date>
    <item>
      <title>Retrieve Macro Parameter Default Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retrieve-Macro-Parameter-Default-Value/m-p/827459#M326861</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was wondering if there is a way to retrieve the default value of a macro parameter in a macro variable or so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro demo (lib=work);
%if &amp;amp;lib.= %str( ) %then 
    %do;
        %let &amp;amp;lib. = &amp;lt;default macro parameter value&amp;gt;;
    %end;
%mend demo;
%demo(lib=);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Aug 2022 10:07:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retrieve-Macro-Parameter-Default-Value/m-p/827459#M326861</guid>
      <dc:creator>xxformat_com</dc:creator>
      <dc:date>2022-08-06T10:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve Macro Parameter Default Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retrieve-Macro-Parameter-Default-Value/m-p/827460#M326862</link>
      <description>&lt;P&gt;Can't you just test if the value is null, set it to WORK (which is the default)??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;lib.= %str( ) %then %let lib=work;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that's not what you want, explain the reason for doing this (I'm asking for reasons, not code).&lt;/P&gt;</description>
      <pubDate>Sat, 06 Aug 2022 10:15:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retrieve-Macro-Parameter-Default-Value/m-p/827460#M326862</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-08-06T10:15:21Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve Macro Parameter Default Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retrieve-Macro-Parameter-Default-Value/m-p/827461#M326863</link>
      <description>&lt;P&gt;Just copy/paste from three lines above. After all,&amp;nbsp;&lt;EM&gt;you&lt;/EM&gt; wrote it into the definition, so&amp;nbsp;&lt;EM&gt;you&lt;/EM&gt;&amp;nbsp;know what to use later in the macro.&lt;/P&gt;</description>
      <pubDate>Sat, 06 Aug 2022 10:33:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retrieve-Macro-Parameter-Default-Value/m-p/827461#M326863</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-08-06T10:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve Macro Parameter Default Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retrieve-Macro-Parameter-Default-Value/m-p/827464#M326865</link>
      <description>&lt;P&gt;Well, it means that the information is maintained in multiple places. If the value is changed in one place, it means that you have to make sure that it is updated everywhere. It requires extra attention to the developer, to the person validation the program and to any one taking over the program. It is just prone to unecessary human error.&lt;/P&gt;</description>
      <pubDate>Sat, 06 Aug 2022 14:05:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retrieve-Macro-Parameter-Default-Value/m-p/827464#M326865</guid>
      <dc:creator>xxformat_com</dc:creator>
      <dc:date>2022-08-06T14:05:05Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve Macro Parameter Default Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retrieve-Macro-Parameter-Default-Value/m-p/827465#M326866</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184742"&gt;@xxformat_com&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was wondering if there is a way to retrieve the default value of a macro parameter in a macro variable or so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro demo (lib=work);
%if &amp;amp;lib.= %str( ) %then 
    %do;
        %let &amp;amp;lib. = &amp;lt;default macro parameter value&amp;gt;;
    %end;
%mend demo;
%demo(lib=);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Just put the default into one place. Move it from the %MACRO statement into your %IF/%THEN logic.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro demo (lib=);
%if 0=%length(&amp;amp;lib) %then %let lib=WORK ;
%put &amp;amp;=lib ;
%mend demo;
%demo(lib=);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also it is much easier to test for empty values by actually testing if the value is empty. By using %LENGTH().&amp;nbsp; If someone goes to the work of using macro quoting so they could pass in a space character that is not an empty value.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Aug 2022 14:21:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retrieve-Macro-Parameter-Default-Value/m-p/827465#M326866</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-06T14:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve Macro Parameter Default Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retrieve-Macro-Parameter-Default-Value/m-p/827467#M326868</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184742"&gt;@xxformat_com&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think with your %IF-%THEN logic you intend to override the default value functionality of the %MACRO statement and hence you don't need the latter, as &lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159" target="_blank" rel="noopener"&gt;Tom&lt;/A&gt; has pointed out already.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If instead you &lt;EM&gt;did&lt;/EM&gt; want to distinguish between the two cases "parameter not specified" and&amp;nbsp;"parameter empty/blank," you could assign the default value to a (local) macro variable to avoid typing the value twice:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(lib=&amp;amp;default);
%local default;
%let default=work;
%put Default parameter value: &amp;amp;default;
%put &amp;amp;=lib;
%mend test;

%test(lib=)
%test()
%test;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 06 Aug 2022 15:17:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retrieve-Macro-Parameter-Default-Value/m-p/827467#M326868</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-08-06T15:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve Macro Parameter Default Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retrieve-Macro-Parameter-Default-Value/m-p/827468#M326869</link>
      <description>&lt;P&gt;That sounds like even more work.&lt;/P&gt;
&lt;P&gt;Personally I just use a macro to validate macro parameters that includes a option to specify the default value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename parmv url "https://raw.githubusercontent.com/sasutils/macros/master/parmv.sas";
%inc parmv;

%macro test(lib);
%parmv(lib,_def=work)
%put &amp;amp;=lib ;
%mend test;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example calls:&lt;/P&gt;
&lt;PRE&gt;2556  %test;
LIB=WORK
2557  %test(sasuser)
LIB=SASUSER
2558  %test(lib=sasuser)
LIB=SASUSER
2559  %test(lib=a b c)

ERROR: TEST user error.
ERROR: A B C is not a valid value for the LIB parameter.
ERROR: The LIB parameter may not have multiple values.
LIB=A B C
&lt;/PRE&gt;</description>
      <pubDate>Sat, 06 Aug 2022 16:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retrieve-Macro-Parameter-Default-Value/m-p/827468#M326869</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-06T16:03:41Z</dc:date>
    </item>
  </channel>
</rss>

