<?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: one macro functions be executed inside another macro function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/one-macro-functions-be-executed-inside-another-macro-function/m-p/386085#M92437</link>
    <description>&lt;P&gt;here is more detail about my cod.still is not executing.appreciate your help to solve my problem..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro macy(x,y,z,index);
%do i=1 %to &amp;amp;index;

ods output FitStatistics=outputt&amp;amp;i;
  data =exercise;
 .........
  if i=1  then repeated/type=&amp;amp;x ;
  else if i=2 then repeated/type=&amp;amp;y;
  else if i=3;then repeated/type=&amp;amp;z;

  end;
 output;
 %end;

   data estout;
  set outputt1 outputt2 outputt3; 
 run; 
  
 %mend macy;   

%macy(un,cs,ar,3);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 07 Aug 2017 17:08:12 GMT</pubDate>
    <dc:creator>fatemeh</dc:creator>
    <dc:date>2017-08-07T17:08:12Z</dc:date>
    <item>
      <title>one macro functions be executed inside another macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/one-macro-functions-be-executed-inside-another-macro-function/m-p/385712#M92303</link>
      <description>&lt;P&gt;hi all.&lt;/P&gt;&lt;P&gt;how can i use a macro function which should be executed&amp;nbsp; inside another macro function ,because the result of inside macro function is needed to be used in the outside macro function .is there any way to do that .if anyone knows that i will appreciate to share it with me.&lt;/P&gt;&lt;P&gt;thanks,&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 16:52:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/one-macro-functions-be-executed-inside-another-macro-function/m-p/385712#M92303</guid>
      <dc:creator>fatemeh</dc:creator>
      <dc:date>2017-08-04T16:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: one macro functions be executed inside another macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/one-macro-functions-be-executed-inside-another-macro-function/m-p/385718#M92306</link>
      <description>&lt;P&gt;With any exising macro you call it in side the other macro as normal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro outer (&amp;lt; your parameters&amp;gt;);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;lt;misc code&amp;gt;&lt;/P&gt;
&lt;P&gt;%othermacro(&amp;lt;its parameters&amp;gt;);&lt;/P&gt;
&lt;P&gt;&amp;lt;other code&amp;gt;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%outer (&amp;lt;parameters&amp;gt;);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some things to consider: You may need to to know the scope of macro variables. If you have the same named macro variable in the outer macro and used in the inner then you may get unexpected results. Also if a macro variable is to be available in the outer macro from the inner then you may need to specify the varaible as %global in the inner macro. Also you need to be careful about using the same names for temporary data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the 'result' a single value, a macro variable or something else? You might post the code for the inner macro and indicate what part needs to be used by the outer macro.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 17:05:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/one-macro-functions-be-executed-inside-another-macro-function/m-p/385718#M92306</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-08-04T17:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: one macro functions be executed inside another macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/one-macro-functions-be-executed-inside-another-macro-function/m-p/386033#M92424</link>
      <description>&lt;P&gt;hi.thanks for your reply .i need to repeat inner macro then combine the results of inner macro and use it in outer macro.&lt;/P&gt;&lt;P&gt;here is some part of the code.how can i have the output1 and output2 and output3 in second macro.&lt;/P&gt;&lt;P&gt;%macro one(x);&lt;/P&gt;&lt;P&gt;data mydata1;&lt;/P&gt;&lt;P&gt;.......output$x;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;%macro two(y);&lt;/P&gt;&lt;P&gt;data mydata2;&lt;/P&gt;&lt;P&gt;set output1 output2&amp;nbsp; output3 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%two(y);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2017 14:38:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/one-macro-functions-be-executed-inside-another-macro-function/m-p/386033#M92424</guid>
      <dc:creator>fatemeh</dc:creator>
      <dc:date>2017-08-07T14:38:41Z</dc:date>
    </item>
    <item>
      <title>Re: one macro functions be executed inside another macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/one-macro-functions-be-executed-inside-another-macro-function/m-p/386055#M92432</link>
      <description>&lt;P&gt;Insufficient information.&lt;/P&gt;
&lt;P&gt;You need to describe you start data a bit and what you are doing. First of all, you "example" code implies that you are defining macro two inside macro one. That is an approach that without a very strong reason is usually a poor choice as changes in the outer may affect the behavior of the inner in unexpected ways. Define each macro separately and provide parameters to receive the values&amp;nbsp;that the second macro may need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If by combine results you need to put the multiple data sets on a set statement then pass a variable with the same index variable that created them and then use that in a do loop.&lt;/P&gt;
&lt;P&gt;A generic loop would look somthing like&lt;/P&gt;
&lt;P&gt;%macro two (index=);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data mydata;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;%do i = 1 %to &amp;amp;index;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output&amp;amp;i&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&amp;nbsp; /*&amp;lt;= this ; ends the SET statement and has nothing to do with the macro language portion*/&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;%mend two;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2017 15:28:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/one-macro-functions-be-executed-inside-another-macro-function/m-p/386055#M92432</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-08-07T15:28:48Z</dc:date>
    </item>
    <item>
      <title>Re: one macro functions be executed inside another macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/one-macro-functions-be-executed-inside-another-macro-function/m-p/386085#M92437</link>
      <description>&lt;P&gt;here is more detail about my cod.still is not executing.appreciate your help to solve my problem..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro macy(x,y,z,index);
%do i=1 %to &amp;amp;index;

ods output FitStatistics=outputt&amp;amp;i;
  data =exercise;
 .........
  if i=1  then repeated/type=&amp;amp;x ;
  else if i=2 then repeated/type=&amp;amp;y;
  else if i=3;then repeated/type=&amp;amp;z;

  end;
 output;
 %end;

   data estout;
  set outputt1 outputt2 outputt3; 
 run; 
  
 %mend macy;   

%macy(un,cs,ar,3);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Aug 2017 17:08:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/one-macro-functions-be-executed-inside-another-macro-function/m-p/386085#M92437</guid>
      <dc:creator>fatemeh</dc:creator>
      <dc:date>2017-08-07T17:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: one macro functions be executed inside another macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/one-macro-functions-be-executed-inside-another-macro-function/m-p/386120#M92448</link>
      <description>&lt;P&gt;The issues of writing a macro 'function' which returns a value are&lt;/P&gt;&lt;P&gt;1. naming conventions&lt;/P&gt;&lt;P&gt;2. scope of returned value: global, or local, and local to which?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;a macro 'function' does not contain any SAS statement semicolons&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;your code shows your macro generating SAS statements, so yes, you want it to 'return' a value&lt;/P&gt;&lt;P&gt;but you cannot use function syntax to do that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;your choice then is to place the returned value in the scope of the calling (outside) macro&lt;/P&gt;&lt;P&gt;or into the global symbol table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%macro max(left,right);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%if &amp;amp;left ge &amp;amp;right %then &amp;amp;left;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%else &amp;amp;right;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%mend;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;*return value into global symbol table;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%let x = %max(3,4);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%put echo &amp;amp;=x;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%macro call_max(data=sashelp.class);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%local x;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%let x = %max(4,5);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%put echo &amp;amp;sysmacroname &amp;amp;=x;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%mend;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%call_max(data=sashelp.shoes)&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;*&lt;/FONT&gt;what&lt;FONT face="courier new,courier"&gt; is the value of X in the global symbol table?;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%put echo &amp;amp;=x;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%macro max_to_global(left,right);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%global x_max;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%if &amp;amp;left ge &amp;amp;right %then %let x_max = &amp;amp;left;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%else %let x_max = &amp;amp;right;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%mend;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%macro call_max_global(data=sashelp.class);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%local x;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%max_to_global(6,7)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%put echo global &amp;amp;=x_max;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%let x = &amp;amp;x_max;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%put echo &amp;amp;sysmacroname &amp;amp;=x;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%mend;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%call_max_global(data=sashelp.shoes)&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;*&lt;/FONT&gt;what&lt;FONT face="courier new,courier"&gt; is the value of X in the global symbol table?;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%put echo &amp;amp;=x &amp;amp;=x_max;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;hth&lt;/P&gt;&lt;P&gt;Ron Fehd&amp;nbsp; macro maven&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2017 19:41:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/one-macro-functions-be-executed-inside-another-macro-function/m-p/386120#M92448</guid>
      <dc:creator>Ron_MacroMaven</dc:creator>
      <dc:date>2017-08-07T19:41:18Z</dc:date>
    </item>
    <item>
      <title>Re: one macro functions be executed inside another macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/one-macro-functions-be-executed-inside-another-macro-function/m-p/386125#M92450</link>
      <description>&lt;P&gt;It really does help to show starting data and what you want at the end.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this supposed to calculate a different variable and place the results in a different data set for each value of the macro variable i?&lt;/P&gt;
&lt;PRE&gt;ods output FitStatistics=outputt&amp;amp;i;
  data =exercise;
 .........
  if i=1  then repeated/type=&amp;amp;x ;
  else if i=2 then repeated/type=&amp;amp;y;
  else if i=3;then repeated/type=&amp;amp;z;

  end;
 output;
&lt;/PRE&gt;
&lt;P&gt;Then you have more problems. In SAS all assignments are with the receiving value on the left of an = sign.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code you seem to be attempting to create: repeated&lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt;type&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;x is going to do weird things.&lt;/P&gt;
&lt;P&gt;If you want to create a variable named UN in the data set and assign the value of repeated/type it should be&lt;/P&gt;
&lt;P&gt;&amp;amp;x = repeated / type;&lt;/P&gt;
&lt;P&gt;The MACRO Variable condition would make it look like this:&lt;/P&gt;
&lt;P&gt;%if &amp;amp;i=1 %then %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;x= repeated / type;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you don't show a set statement or anything about the incoming data I have no understanding of why you have an ODS OUTPUT statement as that is only going to work with a procedure that generated a FitStatistics table. But there is no procedure. So it is confusing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you have a procedure that did what you want before writing any of the macro code? If so show us and we can help you get it into a macro, or possibly determine a macro is not needed at all. If you don't have code that works without the macro then you don't know what the macro is supposed to generate. All the SAS macro language does is generate code but you have to know the code you want it to generate.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2017 19:49:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/one-macro-functions-be-executed-inside-another-macro-function/m-p/386125#M92450</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-08-07T19:49:07Z</dc:date>
    </item>
  </channel>
</rss>

