<?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: Macro variables with underscores in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-variables-with-underscores/m-p/344448#M273045</link>
    <description>&lt;P&gt;Yes, that would mess things up! Try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data somename;
set somename(rename=(
t_b_&amp;amp;input2.5=&amp;amp;input2
));
run;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
    <pubDate>Sun, 26 Mar 2017 20:16:44 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-03-26T20:16:44Z</dc:date>
    <item>
      <title>Macro variables with underscores</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variables-with-underscores/m-p/344410#M273042</link>
      <description>&lt;P&gt;I am a beginner SAS coder and I have the following (excerpt) SAS macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro bts(input1, input2);

proc sql noprint;
select count(*) into :num_record
from b.&amp;amp;input1;
quit;
%put &amp;amp;num_record;


proc sql;
create table c.datafile as
select 
sqrt(&amp;amp;num_record)*(m_&amp;amp;input2/s_&amp;amp;input2+1/3*sum(x_&amp;amp;input2)/(&amp;amp;num_record*s_&amp;amp;input2**3)*(m_&amp;amp;input2/s_&amp;amp;input2)**2+1/(6*&amp;amp;num_record)*sum(x_&amp;amp;input2)/(&amp;amp;num_record*s_&amp;amp;input2**3)) as &amp;amp;input2

from

(select 
mean(&amp;amp;input2) as m_&amp;amp;input2, std(&amp;amp;input2) as s_&amp;amp;input2, (&amp;amp;input2-calculated m_&amp;amp;input2)**3 as x_&amp;amp;input2
from b.&amp;amp;input1);
quit;
%mend;

%bts(inv_per, cr_6m); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The error that I get is:&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;PRE&gt;WARNING: Apparent symbolic reference M_ not resolved.
&amp;amp;m_cr_6m
&lt;/PRE&gt;
&lt;P&gt;The variable cr_6m just consists of numbers and I think the reason I'm getting an error is because of the underscores. How can I fix this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2017 13:03:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variables-with-underscores/m-p/344410#M273042</guid>
      <dc:creator>TrueTears</dc:creator>
      <dc:date>2017-03-26T13:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variables with underscores</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variables-with-underscores/m-p/344417#M273043</link>
      <description>&lt;P&gt;I cannot see how you would get that error message from the code you posted. Can you post the log instead? &amp;nbsp;You could turn on the MPRINT option to see what code the macro is generating.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It really looks like the error message is generated from code like this with a space after the underscore.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;m_ cr_6m&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There is also a posibility that you are trying to generate macro variable name on the fly from other macro variables and the SAS parser is getting confused. &amp;nbsp;This can sometimes be solved by either deriving the name first before using it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let suffix = cr_6m ;
%let mvar= m_&amp;amp;suffix ;
%put value = &amp;amp;&amp;amp;mvar ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or by wrapping the expression in %UNQUOTE() function.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2017 15:18:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variables-with-underscores/m-p/344417#M273043</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-03-26T15:18:28Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variables with underscores</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variables-with-underscores/m-p/344445#M273044</link>
      <description>&lt;P&gt;Ahh, I think I realized my mistake, actually it was in another line:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data somename;
set somename(rename=(
t_b_&amp;amp;input25=&amp;amp;input2
));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The actual name for the variable to be renamed is t_b_cr_6m5, but it's not recognizing the &amp;amp;input2 as cr_6m in the renaming command, how can I fix this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2017 19:43:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variables-with-underscores/m-p/344445#M273044</guid>
      <dc:creator>TrueTears</dc:creator>
      <dc:date>2017-03-26T19:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variables with underscores</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variables-with-underscores/m-p/344448#M273045</link>
      <description>&lt;P&gt;Yes, that would mess things up! Try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data somename;
set somename(rename=(
t_b_&amp;amp;input2.5=&amp;amp;input2
));
run;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2017 20:16:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variables-with-underscores/m-p/344448#M273045</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-26T20:16:44Z</dc:date>
    </item>
  </channel>
</rss>

