<?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 Unable to return value of Macro variable created using call symput in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-return-value-of-Macro-variable-created-using-call/m-p/471033#M120608</link>
    <description>&lt;P&gt;Hi Experts, I am trying to return the value of macro variable that has been created using call symput but I am unable to do so.&lt;/P&gt;
&lt;P&gt;Below is the piece of code I am trying:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro add_sym(a = , b = );&lt;BR /&gt; data _null_;&lt;BR /&gt; call symputx('d',%eval(&amp;amp;a + &amp;amp;b));&lt;BR /&gt; run;&lt;BR /&gt; &amp;amp;d.&lt;BR /&gt;%mend add_sym;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt; sum = %add_sym(a = 1, b = 4);&lt;BR /&gt; put sum = ;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide your expert help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Gurpreet Kaur&lt;/P&gt;</description>
    <pubDate>Mon, 18 Jun 2018 11:13:34 GMT</pubDate>
    <dc:creator>gurpreetkaur</dc:creator>
    <dc:date>2018-06-18T11:13:34Z</dc:date>
    <item>
      <title>Unable to return value of Macro variable created using call symput</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-return-value-of-Macro-variable-created-using-call/m-p/471033#M120608</link>
      <description>&lt;P&gt;Hi Experts, I am trying to return the value of macro variable that has been created using call symput but I am unable to do so.&lt;/P&gt;
&lt;P&gt;Below is the piece of code I am trying:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro add_sym(a = , b = );&lt;BR /&gt; data _null_;&lt;BR /&gt; call symputx('d',%eval(&amp;amp;a + &amp;amp;b));&lt;BR /&gt; run;&lt;BR /&gt; &amp;amp;d.&lt;BR /&gt;%mend add_sym;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt; sum = %add_sym(a = 1, b = 4);&lt;BR /&gt; put sum = ;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide your expert help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Gurpreet Kaur&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 11:13:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-return-value-of-Macro-variable-created-using-call/m-p/471033#M120608</guid>
      <dc:creator>gurpreetkaur</dc:creator>
      <dc:date>2018-06-18T11:13:34Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to return value of Macro variable created using call symput</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-return-value-of-Macro-variable-created-using-call/m-p/471035#M120610</link>
      <description>&lt;P&gt;The macro PREprocessor is just a program text generator, so your code looks like this after the macro has been resolved:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
sum = data _null_;
call symputx('d',%eval(&amp;amp;a + &amp;amp;b));
run;
&amp;amp;d.
put sum = ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which will fail, for very obvious reasons.&lt;/P&gt;
&lt;P&gt;Remove the data step from the macro to make it work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro add_sym(a = , b = );
%let d=%eval(&amp;amp;a + &amp;amp;b);
&amp;amp;d.
%mend add_sym;

data _null_;
sum = %add_sym(a = 1, b = 4);
put sum = ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if you are searching for a language element that helps you simplify calculations within a data step, look into user-defined functions.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 11:41:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-return-value-of-Macro-variable-created-using-call/m-p/471035#M120610</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-06-18T11:41:11Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to return value of Macro variable created using call symput</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-return-value-of-Macro-variable-created-using-call/m-p/471037#M120611</link>
      <description>&lt;P&gt;Why exactly?&amp;nbsp; Macro language is a&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;text only generation tool.&lt;/STRONG&gt;&lt;/U&gt;&amp;nbsp; It is not a language to be doing data processing in.&amp;nbsp; Your doing several implicit conversions here which may or may not be as intended, your also comparing two text values, which don't necessarily convert to numeric, for example consider:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  sum = %add_sym(a = xyz, b = 4);
run;&lt;/PRE&gt;
&lt;P&gt;Its a valid call, but your code will fail, in fact your code will fail in all but exactly integer values.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 12:04:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-return-value-of-Macro-variable-created-using-call/m-p/471037#M120611</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-06-18T12:04:50Z</dc:date>
    </item>
  </channel>
</rss>

