<?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: error when assign macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/error-when-assign-macro-variable/m-p/102796#M21458</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your macro %SUB still has the problem of extraneous semicolons.&amp;nbsp; I'm not sure where you are headed, but here are a couple thoughts.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; Your macro %SUB looks like a macro function, which will return a value.&amp;nbsp; Macro functions should typically not generate any SAS semicolons.&amp;nbsp; I'm assuming you just want to return &amp;amp;c (not &amp;amp;a and &amp;amp;c).&lt;/P&gt;&lt;P&gt;2.&amp;nbsp; The macro variables you created inside the definition of %sub are local to %sub.&amp;nbsp; Typically, it's good to declare the scope of macro variables, so that you ensure they are local to the macro, and avoid collisions with other scopes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Which leads me to below revisions to your code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;70&amp;nbsp;&amp;nbsp; %macro sub(param);
71&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %local a c;
72&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let a=99;
73&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let c = %eval(&amp;amp;param);
74&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put Inside SUB: param=&amp;amp;param a=&amp;amp;a c=&amp;amp;c;
75&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;c&amp;nbsp;&amp;nbsp; /*return this value*/
76&amp;nbsp;&amp;nbsp; %mend sub;
77
78&amp;nbsp;&amp;nbsp; %macro main(exp);
79&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data _null_;
80&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var=%sub(&amp;amp;exp);
81&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put var=;
82&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;
83&amp;nbsp;&amp;nbsp; %mend main;
84
85&amp;nbsp;&amp;nbsp; %main(1+2)
Inside SUB: param=1+2 a=99 c=3

var=3

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH,&lt;/P&gt;&lt;P&gt;--Q.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 11 Jun 2013 16:37:58 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2013-06-11T16:37:58Z</dc:date>
    <item>
      <title>error when assign macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/error-when-assign-macro-variable/m-p/102793#M21455</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have following 3 programs. The 1st and 2nd program ran without error message.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/****************** First Program ******************/&lt;/P&gt;&lt;P&gt;%macro sub(param);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let a=99;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;a;&lt;/P&gt;&lt;P&gt;%mend sub;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro main(exp);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var=%sub(&amp;amp;exp);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put var=;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;%mend main;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%main(1+2)&lt;/P&gt;&lt;P&gt;/****************** First Program ******************/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/****************** Second Program ******************/&lt;/P&gt;&lt;P&gt;%macro sub(param);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let c = %eval(&amp;amp;param);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;c;&lt;/P&gt;&lt;P&gt;%mend sub;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro main(exp);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var=%sub(&amp;amp;exp);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put var=;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;%mend main;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%main(1+2)&lt;/P&gt;&lt;P&gt;/****************** Second Program ******************/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;however,when I ran third program (which is a combination of 1st and 2nd program) , I got error message:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/****************** Third Program ******************/&lt;/P&gt;&lt;P&gt;%macro sub(param);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let a=99;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;a;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let c = %eval(&amp;amp;param);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;c;&lt;/P&gt;&lt;P&gt;%mend sub;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro main(exp);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var=%sub(&amp;amp;exp);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put var=;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;%mend main;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%main(1+2)&lt;/P&gt;&lt;P&gt;/****************** Third Program ******************/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What mistake did I make in the 3rd program? Thank you very much for your help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Jun 2013 14:56:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/error-when-assign-macro-variable/m-p/102793#M21455</guid>
      <dc:creator>newhand</dc:creator>
      <dc:date>2013-06-11T14:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: error when assign macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/error-when-assign-macro-variable/m-p/102794#M21456</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can use the options MPRINT MLOGIC and SYMBOLGEN to debug your macros.&lt;/P&gt;&lt;P&gt;In program3 the main and sub macros generate the following SAS program that contains a syntax error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var=99; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put var=;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Jun 2013 15:32:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/error-when-assign-macro-variable/m-p/102794#M21456</guid>
      <dc:creator>CTorres</dc:creator>
      <dc:date>2013-06-11T15:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: error when assign macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/error-when-assign-macro-variable/m-p/102795#M21457</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Consider the third program (as following), how should I write the program if I want to assign the value of&amp;nbsp; macro variable &lt;STRONG&gt;c&lt;/STRONG&gt; (which is 3) to variable var, &lt;STRONG&gt;without deleting&lt;/STRONG&gt; &lt;STRONG&gt;macro variable a&lt;/STRONG&gt; in macro sub(param)?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/****************** Third Program ******************/&lt;/P&gt;&lt;P&gt;%macro sub(param);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let a=99;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;a;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let c = %eval(&amp;amp;param);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;c;&lt;/P&gt;&lt;P&gt;%mend sub;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro main(exp);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var=%sub(&amp;amp;exp);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put var=;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;%mend main;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%main(1+2)&lt;/P&gt;&lt;P&gt;/****************** Third Program ******************/&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Jun 2013 15:52:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/error-when-assign-macro-variable/m-p/102795#M21457</guid>
      <dc:creator>newhand</dc:creator>
      <dc:date>2013-06-11T15:52:02Z</dc:date>
    </item>
    <item>
      <title>Re: error when assign macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/error-when-assign-macro-variable/m-p/102796#M21458</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your macro %SUB still has the problem of extraneous semicolons.&amp;nbsp; I'm not sure where you are headed, but here are a couple thoughts.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; Your macro %SUB looks like a macro function, which will return a value.&amp;nbsp; Macro functions should typically not generate any SAS semicolons.&amp;nbsp; I'm assuming you just want to return &amp;amp;c (not &amp;amp;a and &amp;amp;c).&lt;/P&gt;&lt;P&gt;2.&amp;nbsp; The macro variables you created inside the definition of %sub are local to %sub.&amp;nbsp; Typically, it's good to declare the scope of macro variables, so that you ensure they are local to the macro, and avoid collisions with other scopes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Which leads me to below revisions to your code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;70&amp;nbsp;&amp;nbsp; %macro sub(param);
71&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %local a c;
72&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let a=99;
73&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let c = %eval(&amp;amp;param);
74&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put Inside SUB: param=&amp;amp;param a=&amp;amp;a c=&amp;amp;c;
75&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;c&amp;nbsp;&amp;nbsp; /*return this value*/
76&amp;nbsp;&amp;nbsp; %mend sub;
77
78&amp;nbsp;&amp;nbsp; %macro main(exp);
79&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data _null_;
80&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var=%sub(&amp;amp;exp);
81&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put var=;
82&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;
83&amp;nbsp;&amp;nbsp; %mend main;
84
85&amp;nbsp;&amp;nbsp; %main(1+2)
Inside SUB: param=1+2 a=99 c=3

var=3

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH,&lt;/P&gt;&lt;P&gt;--Q.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Jun 2013 16:37:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/error-when-assign-macro-variable/m-p/102796#M21458</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2013-06-11T16:37:58Z</dc:date>
    </item>
    <item>
      <title>Re: error when assign macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/error-when-assign-macro-variable/m-p/102797#M21459</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Then you should eliminate the line &amp;amp;a; in the sub macro.&lt;/P&gt;&lt;P&gt;what do you need the &amp;amp;a variable for in this macro?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards, &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Jun 2013 16:56:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/error-when-assign-macro-variable/m-p/102797#M21459</guid>
      <dc:creator>CTorres</dc:creator>
      <dc:date>2013-06-11T16:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: error when assign macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/error-when-assign-macro-variable/m-p/102798#M21460</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much. I am trying to understand how I can transfer variables between different SAS macros. Your answer really helps me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As you have mentioned, this example assumes only one value is returned; may I ask, what if I want to return two values (both a and c) so that variable "var" in MAIN become an array, i.e., var(1)=3, var(2)=99? is it easy to do?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Jun 2013 18:08:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/error-when-assign-macro-variable/m-p/102798#M21460</guid>
      <dc:creator>abcd123</dc:creator>
      <dc:date>2013-06-11T18:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: error when assign macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/error-when-assign-macro-variable/m-p/102799#M21461</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The job of the macro language is (mostly) to generate SAS code, so that you (the programmer) don't have to type it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the above example, there is no transfer of variables between the SAS macros.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The macro %SUB returns a text value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When writing a macro, you need to think about what SAS code you are trying to generate.&amp;nbsp; In your new example, if you would be happy to have %MAIN generate a data step like:&lt;/P&gt;&lt;PRE&gt;data _null_;
&amp;nbsp; array var {2} (99 3);
&amp;nbsp; put var1= var2=;
run;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then you could change the macro sub so that it returns: 99 3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;106&amp;nbsp; %macro sub(param);
107&amp;nbsp;&amp;nbsp;&amp;nbsp; %local a c;
108&amp;nbsp;&amp;nbsp;&amp;nbsp; %let a=99;
109&amp;nbsp;&amp;nbsp;&amp;nbsp; %let c = %eval(&amp;amp;param);
110&amp;nbsp;&amp;nbsp;&amp;nbsp; %put Inside SUB: param=&amp;amp;param a=&amp;amp;a c=&amp;amp;c;
111&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;a &amp;amp;c&amp;nbsp;&amp;nbsp; /*return this value*/
112&amp;nbsp; %mend sub;
113
114&amp;nbsp; %macro main(exp);
115&amp;nbsp;&amp;nbsp;&amp;nbsp; data _null_;
116&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array var {2} (%sub(&amp;amp;exp));
117&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put var1= var2=;
118&amp;nbsp;&amp;nbsp;&amp;nbsp; run;
119&amp;nbsp; %mend main;
120
121&amp;nbsp; %main(1+2)
Inside SUB: param=1+2 a=99 c=3

var1=99 var2=3

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Jun 2013 18:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/error-when-assign-macro-variable/m-p/102799#M21461</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2013-06-11T18:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: error when assign macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/error-when-assign-macro-variable/m-p/102800#M21462</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you want to return a value from a sub macro to the calling environment you could create a global macro variable and hard code the macro to store its return value there.&lt;/P&gt;&lt;P&gt;But it is more flexible if you can avoid that.&amp;nbsp; You could:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) Use function style macro.&amp;nbsp; Works only if macro does not generate any actual SAS code.&lt;/P&gt;&lt;P&gt;2) Pass the name of the variable as a parameter to the macro.&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt; Definition: %macro sub(arg1,arg2,mvar);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; .... %let &amp;amp;mvar = &amp;lt;return value&amp;gt; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Usage:&amp;nbsp; %let score=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %sub(5,6,mvar=score);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put score=&amp;amp;score;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Jun 2013 18:32:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/error-when-assign-macro-variable/m-p/102800#M21462</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-06-11T18:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: error when assign macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/error-when-assign-macro-variable/m-p/102801#M21463</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much. Your answer is very informative!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Jun 2013 18:35:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/error-when-assign-macro-variable/m-p/102801#M21463</guid>
      <dc:creator>abcd123</dc:creator>
      <dc:date>2013-06-11T18:35:02Z</dc:date>
    </item>
  </channel>
</rss>

