<?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 Variable scoping issue when passing parameters to nested inner macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Variable-scoping-issue-when-passing-parameters-to-nested-inner/m-p/16437#M2279</link>
    <description>I have been trying to create some useful autocall macros for use in future programs and I have run into a bit of an implementation problem. &lt;BR /&gt;
&lt;BR /&gt;
I am trying to create a macro that will take the first parameter to determine the type of variables to create and the second parameter to declare what values to assign the variables. Here is what I have so far with a month example&lt;BR /&gt;
&lt;BR /&gt;
%macro ifvar(parm1, parm2);&lt;BR /&gt;
	%if %upcase(&amp;amp;parm1) = MON %then %do;&lt;BR /&gt;
		%if %upcase(&amp;amp;parm2)=JAN %then %do;&lt;BR /&gt;
			data _null_;&lt;BR /&gt;
			     call symput('month', 'January');&lt;BR /&gt;
		             call symput('mm','01');&lt;BR /&gt;
			run;&lt;BR /&gt;
		%end;	&lt;BR /&gt;
&lt;BR /&gt;
		%if %upcase(&amp;amp;parm2)=FEB %then %do;&lt;BR /&gt;
		        data _null_;&lt;BR /&gt;
			    call symput('mm','02');&lt;BR /&gt;
			    call symput('month','February');&lt;BR /&gt;
			run;&lt;BR /&gt;
		%end;&lt;BR /&gt;
                ..........&lt;BR /&gt;
	%end;&lt;BR /&gt;
&lt;BR /&gt;
	%if %upcase(&amp;amp;parm1) = MM %then %do;&lt;BR /&gt;
		%if %upcase(&amp;amp;parm2)=01 %then %do;&lt;BR /&gt;
			data _null_;&lt;BR /&gt;
			    call symput('month','January');&lt;BR /&gt;
			    call symput('mon','jan');&lt;BR /&gt;
			run;&lt;BR /&gt;
		%end;&lt;BR /&gt;
                ..............&lt;BR /&gt;
	%end;&lt;BR /&gt;
         ..................&lt;BR /&gt;
%mend ifvar;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
The problem is that %ifvar creates parm1 and parm2 in its local table so the new variables all get created there and when I try to pass it to the outer table in a dummy macro it comes out empty. I am able to get them to pass to an outer table if I take out the parameters and simply declare them with a %local and %let statement in the outer macro but this seems to defeat the purpose of parameters. &lt;BR /&gt;
&lt;BR /&gt;
Any suggestions for how to deal with this or advice on what I am doing wrong? I am trying to avoid having to declare a global variable list each time this macro is run to keep things tight but I am thinking that may be the only answer.&lt;BR /&gt;
-Thanks</description>
    <pubDate>Wed, 13 Oct 2010 18:34:32 GMT</pubDate>
    <dc:creator>johns576</dc:creator>
    <dc:date>2010-10-13T18:34:32Z</dc:date>
    <item>
      <title>Variable scoping issue when passing parameters to nested inner macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-scoping-issue-when-passing-parameters-to-nested-inner/m-p/16437#M2279</link>
      <description>I have been trying to create some useful autocall macros for use in future programs and I have run into a bit of an implementation problem. &lt;BR /&gt;
&lt;BR /&gt;
I am trying to create a macro that will take the first parameter to determine the type of variables to create and the second parameter to declare what values to assign the variables. Here is what I have so far with a month example&lt;BR /&gt;
&lt;BR /&gt;
%macro ifvar(parm1, parm2);&lt;BR /&gt;
	%if %upcase(&amp;amp;parm1) = MON %then %do;&lt;BR /&gt;
		%if %upcase(&amp;amp;parm2)=JAN %then %do;&lt;BR /&gt;
			data _null_;&lt;BR /&gt;
			     call symput('month', 'January');&lt;BR /&gt;
		             call symput('mm','01');&lt;BR /&gt;
			run;&lt;BR /&gt;
		%end;	&lt;BR /&gt;
&lt;BR /&gt;
		%if %upcase(&amp;amp;parm2)=FEB %then %do;&lt;BR /&gt;
		        data _null_;&lt;BR /&gt;
			    call symput('mm','02');&lt;BR /&gt;
			    call symput('month','February');&lt;BR /&gt;
			run;&lt;BR /&gt;
		%end;&lt;BR /&gt;
                ..........&lt;BR /&gt;
	%end;&lt;BR /&gt;
&lt;BR /&gt;
	%if %upcase(&amp;amp;parm1) = MM %then %do;&lt;BR /&gt;
		%if %upcase(&amp;amp;parm2)=01 %then %do;&lt;BR /&gt;
			data _null_;&lt;BR /&gt;
			    call symput('month','January');&lt;BR /&gt;
			    call symput('mon','jan');&lt;BR /&gt;
			run;&lt;BR /&gt;
		%end;&lt;BR /&gt;
                ..............&lt;BR /&gt;
	%end;&lt;BR /&gt;
         ..................&lt;BR /&gt;
%mend ifvar;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
The problem is that %ifvar creates parm1 and parm2 in its local table so the new variables all get created there and when I try to pass it to the outer table in a dummy macro it comes out empty. I am able to get them to pass to an outer table if I take out the parameters and simply declare them with a %local and %let statement in the outer macro but this seems to defeat the purpose of parameters. &lt;BR /&gt;
&lt;BR /&gt;
Any suggestions for how to deal with this or advice on what I am doing wrong? I am trying to avoid having to declare a global variable list each time this macro is run to keep things tight but I am thinking that may be the only answer.&lt;BR /&gt;
-Thanks</description>
      <pubDate>Wed, 13 Oct 2010 18:34:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-scoping-issue-when-passing-parameters-to-nested-inner/m-p/16437#M2279</guid>
      <dc:creator>johns576</dc:creator>
      <dc:date>2010-10-13T18:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: Variable scoping issue when passing parameters to nested inner macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-scoping-issue-when-passing-parameters-to-nested-inner/m-p/16438#M2280</link>
      <description>Hi:&lt;BR /&gt;
  You might want to read the section in the macro documentation on scoping issues. The %LOCAL and %GLOBAL statements exist for the purpose of allowing you to control which symbol table your macro variables are stored in.&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a001072111.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a001072111.htm&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000206835.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000206835.htm&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000206954.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000206954.htm&lt;/A&gt;&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 13 Oct 2010 19:46:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-scoping-issue-when-passing-parameters-to-nested-inner/m-p/16438#M2280</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-10-13T19:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: Variable scoping issue when passing parameters to nested inner macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-scoping-issue-when-passing-parameters-to-nested-inner/m-p/16439#M2281</link>
      <description>This is nothing to do with either nesting of macros,   passing parameters or symbol tables. This is so simple in macro that I am not even sure these deserve to be autocall'ed. Hope this helps.&lt;BR /&gt;
[pre]&lt;BR /&gt;
   %macro mon2mm(mon);&lt;BR /&gt;
     %sysfunc(putn("01&amp;amp;mon.2000"d,mmyy5),2) &lt;BR /&gt;
   %mend  mon2mm;&lt;BR /&gt;
   %macro mm2mon(mm);&lt;BR /&gt;
     %sysfunc(inputn(&amp;amp;mm./01/2000,mmddyy10),monname3)&lt;BR /&gt;
   %mend mm2mon;&lt;BR /&gt;
&lt;BR /&gt;
   %put %mon2mm(Jan) %mon2mm(Feb) %mon2mm(Mar) %mon2mm(Nov) %mon2mm(Dec);&lt;BR /&gt;
   %put %mm2mon(01) %mm2mon(2) %mm2mon(3) %mm2mon(11) %mm2mon(12);&lt;BR /&gt;
   %*-- on log&lt;BR /&gt;
   01 02 03 11 12&lt;BR /&gt;
   Jan Feb Mar Nov Dec&lt;BR /&gt;
   --*;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 14 Oct 2010 15:36:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-scoping-issue-when-passing-parameters-to-nested-inner/m-p/16439#M2281</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2010-10-14T15:36:07Z</dc:date>
    </item>
  </channel>
</rss>

