<?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: Returning a value from another macro from within a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Returning-a-value-from-another-macro-from-within-a-macro/m-p/79607#M17136</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Agree with Tom. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I appreciate CPAZ posting good sample data.&amp;nbsp; I'm confused by the design.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Seems to me you've gone to a lot of work to mak %main_macro be close to a macro function.&amp;nbsp; So you use SCL functions to loop through the dataset.&amp;nbsp; But it can't be a true macro function, because it generates SAS language statements (CALL EXECUTE) with a SAS language semicolon.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are of course lots of ways to do this lookup (could be a merge, or a format, or whatever).&amp;nbsp; Might be helpful if you could describe more of the big picture of your goal, and why you are taking this approach rather than doing a more traditional lookup.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;--Q.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 12 Sep 2013 14:40:31 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2013-09-12T14:40:31Z</dc:date>
    <item>
      <title>Returning a value from another macro from within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-a-value-from-another-macro-from-within-a-macro/m-p/79602#M17131</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know this might seem trivial, but I have tried several methods for this. The problem is this, I want to call a simple macro (prodrow_lookup) from within the (main_macro) to perform a simple lookup and return the value as a macro variable, or just return the value period. (see code below). I need to keep the data _null_ statement inside the (main_macro) due to some other constraints. But I get the following result from the %put statement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;**** returnCode =&lt;/P&gt;&lt;P&gt;**** returnCode =&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I should (would like to) get:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;**** returnCode = 9&lt;/P&gt;&lt;P&gt;****returnCode = 4&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help will be greatly appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;%global&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt; returnCode;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;%let returnCode=;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;data prods;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;length&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt; product_type $ &lt;/SPAN&gt;&lt;STRONG style=": ; color: #008080; font-size: 12pt; font-family: Courier New;"&gt;12&lt;/STRONG&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt; count product_type $;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;datalines&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;9 Firebird&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;4 Trails&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000080; font-size: 12pt; font-family: Courier New;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;data outputdata;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;length&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt; product_type $ &lt;/SPAN&gt;&lt;STRONG style=": ; color: #008080; font-size: 12pt; font-family: Courier New;"&gt;12&lt;/STRONG&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt; product_type $;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;datalines&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;Firebird&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;Trails&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;%macro prodrow_lookup(prod=);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt; %let&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt; myvar=&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;%str&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;(%'&amp;amp;prod%');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt; proc sql; select count into :returnCode from prods where product_type = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;%unquote&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;(&amp;amp;myvar);quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;%mend prodrow_lookup;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;%macro main_macro(data=);&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;&lt;SPAN style="color: #0000ff;"&gt;%local&lt;/SPAN&gt; dsid rc rownum rows cols;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;&lt;SPAN style="color: #0000ff;"&gt;%let&lt;/SPAN&gt; dsid = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;(open(&amp;amp;data));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;&lt;SPAN style="color: #0000ff;"&gt;%let&lt;/SPAN&gt; rows=&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;(attrn(&amp;amp;dsid,nobs));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;&lt;SPAN style="color: #0000ff;"&gt;%let&lt;/SPAN&gt; cols=&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;(attrn(&amp;amp;dsid,nvars));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New; font-size: 12pt;"&gt;&lt;SPAN style="font-family: Courier New; font-size: 12pt;"&gt;%do &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;%while&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt; (&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;(fetch(&amp;amp;dsid)) = &lt;/SPAN&gt;&lt;STRONG style=": ; color: #008080; font-size: 12pt; font-family: Courier New;"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;); &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 12pt; font-family: Courier New;"&gt;/* outloop across rows */&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt; c = &lt;/SPAN&gt;&lt;STRONG style=": ; color: #008080; font-size: 12pt; font-family: Courier New;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;%to&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt; &amp;amp;cols; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 12pt; font-family: Courier New;"&gt;/* inner loop acrodd columns of a given rows */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %local&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt; v t &amp;amp;v;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt; v = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;(varname(&amp;amp;dsid,&amp;amp;c));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt; t = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;(vartype(&amp;amp;dsid, &amp;amp;c)); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt; &amp;amp;v = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;(getvar&amp;amp;t(&amp;amp;dsid, &amp;amp;c));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 12pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if &amp;amp;c = &lt;/SPAN&gt;&lt;STRONG style=": ; color: #008080; font-size: 12pt; font-family: Courier New;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt; then do; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 12pt; font-family: Courier New;"&gt;/* if I find a specific column, then execute macro prodrow_lookup */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 12pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute(&lt;/SPAN&gt;&lt;SPAN style="color: #800080; font-size: 12pt; font-family: Courier New;"&gt;'%prodrow_lookup(prod=&amp;amp;&amp;amp;&amp;amp;v)'&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt; **** returnCode = &amp;amp;returnCode; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-size: 12pt; font-family: Courier New;"&gt;/* print the output of prodrow_lookup */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000; font-size: 12pt; font-family: Courier New;"&gt;&lt;SPAN style="color: #333333;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp; %end&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;%end&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt; rc = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 12pt; font-family: Courier New;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;(close(&amp;amp;dsid));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 12pt; font-family: Courier New;"&gt;%mend&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt; main_macro;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;%main_macro(data=work.outputdata);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: Courier New;"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 02:39:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-a-value-from-another-macro-from-within-a-macro/m-p/79602#M17131</guid>
      <dc:creator>CPAZ</dc:creator>
      <dc:date>2013-09-12T02:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: Returning a value from another macro from within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-a-value-from-another-macro-from-within-a-macro/m-p/79603#M17132</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I understood properly the limitations of macro functions vs macro routines in Macro II course, since you are retrieving the macro variable value from non-macro code, you have to go with a routine (as your current code is designed).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, unless specified otherwise, all macro variables inside a macro are local macro variables. Thus, even though you have&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 12pt;"&gt;%global&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 12pt;"&gt; returnCode;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 12pt;"&gt;%let returnCode=;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 12pt;"&gt;outside the definition of %prodrow_lookup, the one created inside the macro is only local to the macro (and indirectly restrain the access to the global returncode from within the macro because a local scope variable of the same name exists).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 12pt;"&gt;%macro prodrow_lookup(prod=);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 12pt;"&gt;&amp;nbsp; %global&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 12pt;"&gt; returnCode;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New; font-size: 12pt;"&gt; %let&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 12pt;"&gt; myvar=&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New; font-size: 12pt;"&gt;%str&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 12pt;"&gt;(%'&amp;amp;prod%');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 12pt;"&gt; proc sql; select count into :returnCode from prods where product_type = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New; font-size: 12pt;"&gt;%unquote&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 12pt;"&gt;(&amp;amp;myvar);quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 12pt;"&gt;%mend prodrow_lookup;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 12pt;"&gt;The above *should* fix your issue. Another alternative would be to make %prodlow_lookup be a macro function that only parses the code&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;proc sql; select count into :returnCode from prods where product_type = &lt;SPAN style="color: #0000ff; font-family: Courier New; font-size: 12pt;"&gt;%unquote&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 12pt;"&gt;(&amp;amp;myvar);quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 12pt;"&gt;into your outer macro effectively creating the :returnCode locally to the outer macro rather than the inner.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 12pt;"&gt;Vincent&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 12:20:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-a-value-from-another-macro-from-within-a-macro/m-p/79603#M17132</guid>
      <dc:creator>Vince28_Statcan</dc:creator>
      <dc:date>2013-09-12T12:20:34Z</dc:date>
    </item>
    <item>
      <title>Re: Returning a value from another macro from within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-a-value-from-another-macro-from-within-a-macro/m-p/79604#M17133</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;%global returnCode;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;*delete the %let returncode=;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data prods;&lt;/P&gt;&lt;P&gt;length product_type $ 12;&lt;/P&gt;&lt;P&gt;input count product_type $;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;9 Firebird&lt;/P&gt;&lt;P&gt;4 Trails&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data outputdata;&lt;/P&gt;&lt;P&gt;length product_type $ 12;&lt;/P&gt;&lt;P&gt;input product_type $;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;Firebird&lt;/P&gt;&lt;P&gt;Trails&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro prodrow_lookup(prod=);&lt;/P&gt;&lt;P&gt;proc sql noprint; select count into :returnCode from prods where strip(product_type) =&lt;SPAN style="text-decoration: underline;"&gt; "&amp;amp;prod"&lt;/SPAN&gt;;quit; &lt;/P&gt;&lt;P&gt;%mend prodrow_lookup;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro main_macro(data=); &lt;/P&gt;&lt;P&gt;%local dsid rc rownum rows cols;&lt;/P&gt;&lt;P&gt;%let dsid = %sysfunc(open(&amp;amp;data));&lt;/P&gt;&lt;P&gt;%let rows=%sysfunc(attrn(&amp;amp;dsid,nobs));&lt;/P&gt;&lt;P&gt;%let cols=%sysfunc(attrn(&amp;amp;dsid,nvars));&lt;/P&gt;&lt;P&gt; data _null_;&lt;/P&gt;&lt;P&gt;%do %while (%sysfunc(fetch(&amp;amp;dsid)) = 0); /* outloop across rows */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do c = 1 %to &amp;amp;cols; /* inner loop acrodd columns of a given rows */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %local v t &amp;amp;v;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let v = %sysfunc(varname(&amp;amp;dsid,&amp;amp;c));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let t = %sysfunc(vartype(&amp;amp;dsid, &amp;amp;c));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="text-decoration: underline;"&gt;&amp;nbsp; %let d = %sysfunc(getvar&amp;amp;t(&amp;amp;dsid, &amp;amp;c));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="text-decoration: underline;"&gt;&amp;nbsp; %if &amp;amp;c = 1 %then %do&lt;/SPAN&gt;; /* if I find a specific column, then execute macro prodrow_lookup */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute('%prodrow_lookup(prod=&lt;SPAN style="text-decoration: underline;"&gt;&amp;amp;d&lt;/SPAN&gt;)');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put **** returnCode = &amp;amp;returnCode; /* print the output of prodrow_lookup */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%let rc = %sysfunc(close(&amp;amp;dsid));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%mend main_macro;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%main_macro(data=work.outputdata);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 13:48:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-a-value-from-another-macro-from-within-a-macro/m-p/79604#M17133</guid>
      <dc:creator>sandyming</dc:creator>
      <dc:date>2013-09-12T13:48:32Z</dc:date>
    </item>
    <item>
      <title>Re: Returning a value from another macro from within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-a-value-from-another-macro-from-within-a-macro/m-p/79605#M17134</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This doesn't look like a macro issue.&amp;nbsp; Instead it is the issue of timing of execution of code generated by CALL EXECUTE.&amp;nbsp; When you submit code to run with CALL EXECUTE it will run after the current step has finished.&amp;nbsp; So there is no way that the currently executing data step can see the results of your PROC SQL code which will actually run after the data step has finished.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 14:02:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-a-value-from-another-macro-from-within-a-macro/m-p/79605#M17134</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-09-12T14:02:50Z</dc:date>
    </item>
    <item>
      <title>Re: Returning a value from another macro from within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-a-value-from-another-macro-from-within-a-macro/m-p/79606#M17135</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, I know we're only seeing part of the picture.&amp;nbsp; After all, there is nothing about your code that requires the data _null_ statement to remain in place.&amp;nbsp; (CALL EXECUTE could be converted to a direct call to the macro if the DATA statement were removed.)&amp;nbsp; With that in mind, this solution would work but you'll have to decide if it does what you need in context.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Move the %PUT statement.&amp;nbsp; %put **** Return code = &amp;amp;returnCode;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Make it the last statement in %PRODROW_LOOKUP instead of being part of the main macro.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you have other constraints that make that impossible, you'll have to spell them out.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 14:32:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-a-value-from-another-macro-from-within-a-macro/m-p/79606#M17135</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-09-12T14:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: Returning a value from another macro from within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-a-value-from-another-macro-from-within-a-macro/m-p/79607#M17136</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Agree with Tom. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I appreciate CPAZ posting good sample data.&amp;nbsp; I'm confused by the design.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Seems to me you've gone to a lot of work to mak %main_macro be close to a macro function.&amp;nbsp; So you use SCL functions to loop through the dataset.&amp;nbsp; But it can't be a true macro function, because it generates SAS language statements (CALL EXECUTE) with a SAS language semicolon.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are of course lots of ways to do this lookup (could be a merge, or a format, or whatever).&amp;nbsp; Might be helpful if you could describe more of the big picture of your goal, and why you are taking this approach rather than doing a more traditional lookup.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;--Q.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 14:40:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-a-value-from-another-macro-from-within-a-macro/m-p/79607#M17136</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2013-09-12T14:40:31Z</dc:date>
    </item>
    <item>
      <title>Re: Returning a value from another macro from within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-a-value-from-another-macro-from-within-a-macro/m-p/79608#M17137</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree that Call Execute is the main problem here. It is a timing problem where the macro variable are resolved prior to the execution. So the best option is maybe to avoid call execute. But it can probably be solved by adding %nrstr to the call.like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;call execute('%nrstr(%prodrow_lookup(prod=&amp;amp;d))');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then calling a macro from call execute&amp;nbsp; will behave almost like an ordinary macro call.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/Svein Erik &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Sep 2013 07:48:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-a-value-from-another-macro-from-within-a-macro/m-p/79608#M17137</guid>
      <dc:creator>SveinE</dc:creator>
      <dc:date>2013-09-13T07:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: Returning a value from another macro from within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-a-value-from-another-macro-from-within-a-macro/m-p/79609#M17138</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, forget about this %nrstr suggesting. In this contex it did not work. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Maybe this will do:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if &amp;amp;c = 1 %then %do; /* if I find a specific column, then execute macro prodrow_lookup */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; *call execute('%prodrow_lookup(prod=&amp;amp;&amp;amp;&amp;amp;v)');&lt;/P&gt;&lt;P&gt;&amp;nbsp; %prodrow_lookup(prod=&amp;amp;&amp;amp;&amp;amp;v);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %put **** returnCode = &amp;amp;returnCode; /* print the output of prodrow_lookup */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Sep 2013 08:56:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-a-value-from-another-macro-from-within-a-macro/m-p/79609#M17138</guid>
      <dc:creator>SveinE</dc:creator>
      <dc:date>2013-09-13T08:56:35Z</dc:date>
    </item>
  </channel>
</rss>

