<?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 SAS Tip: Setting Default Values for Macro Parameters in SAS Tips from the Community</title>
    <link>https://communities.sas.com/t5/SAS-Tips-from-the-Community/SAS-Tip-Setting-Default-Values-for-Macro-Parameters/m-p/442558#M141</link>
    <description>&lt;P&gt;Quite often it is necessary to set a default value for a macro variable or parameter that is passed to a program. If the program is a macro, the &lt;A href="http://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n18fij8dqsue9pn1lp8436e5mvb7.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;%IF statement&lt;/A&gt; can be used to check if the value is provided and provide a default value if not. Since the %IF statements are not allowed outside of macros, that technique won't work for a non-macro program (e.g., a file/program that is &lt;STRONG&gt;%INCLUDE&lt;/STRONG&gt;d). The following code snippet demonstrates the use of the &lt;A href="http://documentation.sas.com/?docsetId=fedsqlref&amp;amp;docsetTarget=n0crpo0xd76wb3n1poba9wmu1a6q.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;coalescec&lt;/A&gt; function to assign a default value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global myParameter;  /* ensure it exists */
%let myParameter = %sysfunc(coalescec(&amp;amp;myParameter,defaultValue));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the &lt;STRONG&gt;myParameter&lt;/STRONG&gt; macro variable&amp;nbsp;has a value, it will be used, otherwise &lt;STRONG&gt;defaultValue&lt;/STRONG&gt;&amp;nbsp;will be assigned as the value. This technique can also be used in macros instead of using a %IF statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The coalescec function is used regardless of whether the expected value for the parameter is numeric&amp;nbsp;since macro is a text manipulation facility, (i.e., everything in macro is interpreted as a character string).&lt;/P&gt;
&lt;HR /&gt;
&lt;P&gt;Thanks to Don Henderson&amp;nbsp;for sharing this tip on sasCommunity.org.&lt;/P&gt;</description>
    <pubDate>Fri, 23 Mar 2018 19:04:23 GMT</pubDate>
    <dc:creator>SAS_Tipster</dc:creator>
    <dc:date>2018-03-23T19:04:23Z</dc:date>
    <item>
      <title>SAS Tip: Setting Default Values for Macro Parameters</title>
      <link>https://communities.sas.com/t5/SAS-Tips-from-the-Community/SAS-Tip-Setting-Default-Values-for-Macro-Parameters/m-p/442558#M141</link>
      <description>&lt;P&gt;Quite often it is necessary to set a default value for a macro variable or parameter that is passed to a program. If the program is a macro, the &lt;A href="http://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n18fij8dqsue9pn1lp8436e5mvb7.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;%IF statement&lt;/A&gt; can be used to check if the value is provided and provide a default value if not. Since the %IF statements are not allowed outside of macros, that technique won't work for a non-macro program (e.g., a file/program that is &lt;STRONG&gt;%INCLUDE&lt;/STRONG&gt;d). The following code snippet demonstrates the use of the &lt;A href="http://documentation.sas.com/?docsetId=fedsqlref&amp;amp;docsetTarget=n0crpo0xd76wb3n1poba9wmu1a6q.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;coalescec&lt;/A&gt; function to assign a default value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global myParameter;  /* ensure it exists */
%let myParameter = %sysfunc(coalescec(&amp;amp;myParameter,defaultValue));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the &lt;STRONG&gt;myParameter&lt;/STRONG&gt; macro variable&amp;nbsp;has a value, it will be used, otherwise &lt;STRONG&gt;defaultValue&lt;/STRONG&gt;&amp;nbsp;will be assigned as the value. This technique can also be used in macros instead of using a %IF statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The coalescec function is used regardless of whether the expected value for the parameter is numeric&amp;nbsp;since macro is a text manipulation facility, (i.e., everything in macro is interpreted as a character string).&lt;/P&gt;
&lt;HR /&gt;
&lt;P&gt;Thanks to Don Henderson&amp;nbsp;for sharing this tip on sasCommunity.org.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2018 19:04:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Tips-from-the-Community/SAS-Tip-Setting-Default-Values-for-Macro-Parameters/m-p/442558#M141</guid>
      <dc:creator>SAS_Tipster</dc:creator>
      <dc:date>2018-03-23T19:04:23Z</dc:date>
    </item>
  </channel>
</rss>

