<?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: Sas macro parameter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sas-macro-parameter/m-p/557868#M155588</link>
    <description>&lt;P&gt;The macro should have a variable that you access (by using an ampersand) inside the macro, like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro TEST(Table=);
&amp;nbsp; &amp;nbsp;%put &amp;amp;Table;&amp;nbsp; &amp;nbsp; &amp;nbsp;/* name of the macro variable is Table. The value is &amp;amp;Table */
%mend;

%TEST(table=DBName.TableName);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that doesn't answer your question, please show the signature of the %TEST macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 10 May 2019 16:45:28 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2019-05-10T16:45:28Z</dc:date>
    <item>
      <title>Sas macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-macro-parameter/m-p/557865#M155585</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a SAS macro that takes in a parameter in this format:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro TEST(DBName.TableName);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is preferred to have just a single argument so I'm not looking to pass on DBName and TableName as 2 separate parameters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm facing the following concerns with this approach:&lt;/P&gt;&lt;P&gt;1. Is this the right syntax to define a macro with such parameter?&lt;/P&gt;&lt;P&gt;2. How do I reference this parameter within the macro? I'm doing a basic sql query within the macro to access it:&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select top 500 * from &amp;amp;DBName.TableName.;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Log gives me these errors, as expected:&lt;/P&gt;&lt;P&gt;ERROR: Symbolic variable name DBNAME.TABLENAME must contain only letters, digits, and underscores.&lt;BR /&gt;ERROR: Invalid macro parameter name DBNAME.TABLENAME. It should be a valid SAS identifier no longer than 32 characters.&lt;BR /&gt;ERROR: A dummy macro will be compiled.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate any help!&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2019 16:34:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-macro-parameter/m-p/557865#M155585</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-05-10T16:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: Sas macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-macro-parameter/m-p/557868#M155588</link>
      <description>&lt;P&gt;The macro should have a variable that you access (by using an ampersand) inside the macro, like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro TEST(Table=);
&amp;nbsp; &amp;nbsp;%put &amp;amp;Table;&amp;nbsp; &amp;nbsp; &amp;nbsp;/* name of the macro variable is Table. The value is &amp;amp;Table */
%mend;

%TEST(table=DBName.TableName);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that doesn't answer your question, please show the signature of the %TEST macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2019 16:45:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-macro-parameter/m-p/557868#M155588</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-05-10T16:45:28Z</dc:date>
    </item>
    <item>
      <title>Re: Sas macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-macro-parameter/m-p/557874#M155592</link>
      <description>&lt;P&gt;So the main purpose of doing this is to let other folks using this macro is to let them know what input parameters they are expected to send when they use this macro in their codes. If I name the macro variable as 'table', they wouldn't know that they need to send the complete name with the database name, hence something like dbname.tablename needs to be mentioned in the arguments being passed so that they know the exact format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2019 16:51:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-macro-parameter/m-p/557874#M155592</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-05-10T16:51:46Z</dc:date>
    </item>
    <item>
      <title>Re: Sas macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-macro-parameter/m-p/557889#M155596</link>
      <description>&lt;P&gt;OK, then use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrobound"&gt;%macro&lt;/SPAN&gt; TEST&lt;SPAN class="token punctuation"&gt;(&lt;SPAN&gt;DBname_TableName&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
...
&lt;SPAN class="token macrobound"&gt;%mend&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error you're getting is because periods ("dot") are not permitted in SAS variable names. Also, the period is used to terminate a macro reference, so in the statement&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;select top 500 * from &amp;amp;DBName.TableName.;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;the first period ends the macro and SAS is looking for the macro variable DBName so that it can figure out how to resolve &amp;amp;DBName. and then append the string TableName to it.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2019 17:07:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-macro-parameter/m-p/557889#M155596</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-05-10T17:07:28Z</dc:date>
    </item>
    <item>
      <title>Re: Sas macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-macro-parameter/m-p/557891#M155597</link>
      <description>&lt;P&gt;That makes sense, I think I can do that. For some reason I was under the impression that the dot in the actual parameter needs to reflect in the parameter call as well. This was helpful, thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2019 17:12:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-macro-parameter/m-p/557891#M155597</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-05-10T17:12:26Z</dc:date>
    </item>
    <item>
      <title>Re: Sas macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-macro-parameter/m-p/557908#M155604</link>
      <description>&lt;P&gt;One of the nice features of how SAS macros work is the ability to call the macro using the parameter name, even for parameters that the macro also allows you call by position.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you defined a macro using a positional parameter like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro myreport(table);
 .... &amp;amp;table. ....
%mend myreport;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Users can then call it in two ways.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%myreport(mylibref.mymembername)
%myreport(table=mylibref.mymembername)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you use the second style in your code that calls the macro then readers of your code have a better idea of&amp;nbsp; the meaning of the value being passed since they can see both the value the calling code is passing and the name that the macro has given for the parameter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2019 18:14:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-macro-parameter/m-p/557908#M155604</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-10T18:14:52Z</dc:date>
    </item>
  </channel>
</rss>

