<?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: Declaring multiple global macro variables within a %macro with proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Declaring-multiple-global-macro-variables-within-a-macro-with/m-p/414868#M101690</link>
    <description>&lt;P&gt;Have your macro generate a %GLOBAL statement, before the related PROC SQL executes.&amp;nbsp; (PROC SQL can populate global variables, but it cannot create global variables when used inside of a macro.)&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%global Coeff_%scan(&amp;amp;INPUTS_EF.,&amp;amp;i.);&lt;/P&gt;
&lt;P&gt;%global Slope_%scan(&amp;amp;INPUTS_EF.&amp;amp;i.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are a few places to insert such statements, but they'll work just fine as long as they precede the SQL INTO : that populates the variable.&lt;/P&gt;</description>
    <pubDate>Mon, 20 Nov 2017 15:29:02 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-11-20T15:29:02Z</dc:date>
    <item>
      <title>Declaring multiple global macro variables within a %macro with proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Declaring-multiple-global-macro-variables-within-a-macro-with/m-p/414861#M101685</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote this macro to create multiple macro variables that I will use later in my program. The code works juste fine, however if I want to call these macro variables later in open code, I need to make them global if I understand correctly. Is there a way to implement this easily in my code so that all these macro variables can be called later?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO INPUTS_PARAMETERS 	();

		proc sql ;
			select Intercept
			into :Intercept
			from EXTLIB.COEFF_REFERENCE
		;

	%do i=1 %to %sysfunc(countw(&amp;amp;INPUTS_EF.));

		proc sql ;
			select T_%scan(&amp;amp;INPUTS_EF.,&amp;amp;i.)_M801010
			into :Coeff_%scan(&amp;amp;INPUTS_EF.,&amp;amp;i.)
			from EXTLIB.COEFF_REFERENCE
		;
			proc sql ;
				select Slope
				into :Slope_%scan(&amp;amp;INPUTS_EF.,&amp;amp;i.)
				from EXTLIB.TRANSFO_PARAMS_GLOBAL
				where Variable = "%scan(&amp;amp;INPUTS_EF.,&amp;amp;i.)_M801010"
			;
				proc sql ;
					select Midpoint
					into :Midpoint_%scan(&amp;amp;INPUTS_EF.,&amp;amp;i.)
					from EXTLIB.TRANSFO_PARAMS_GLOBAL
					where Variable = "%scan(&amp;amp;INPUTS_EF.,&amp;amp;i.)_M801010"
				;
	
	%end;

	%do i=1 %to %sysfunc(countw(&amp;amp;INPUTS_SEC.));

		proc sql ;
			select %scan(&amp;amp;INPUTS_SEC.,&amp;amp;i.)
			into :Coeff_%scan(&amp;amp;INPUTS_SEC.,&amp;amp;i.)
			from EXTLIB.COEFF_REFERENCE
		;
		quit;
	%end;
		


%MEND INPUTS_PARAMETERS;

%INPUTS_PARAMETERS ();&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Nov 2017 15:14:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Declaring-multiple-global-macro-variables-within-a-macro-with/m-p/414861#M101685</guid>
      <dc:creator>x2PSx</dc:creator>
      <dc:date>2017-11-20T15:14:17Z</dc:date>
    </item>
    <item>
      <title>Re: Declaring multiple global macro variables within a %macro with proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Declaring-multiple-global-macro-variables-within-a-macro-with/m-p/414864#M101688</link>
      <description>&lt;P&gt;The first thing that comes to mind is using data steps with call symputx('name','value','g'); instead of the SQL's.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OTOH, creating lists of macro variables is something I tend to avoid. I rather create code with call execute from datasets, so I don't have to keep counts and so on.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2017 15:19:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Declaring-multiple-global-macro-variables-within-a-macro-with/m-p/414864#M101688</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-20T15:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: Declaring multiple global macro variables within a %macro with proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Declaring-multiple-global-macro-variables-within-a-macro-with/m-p/414865#M101689</link>
      <description>&lt;P&gt;I would tend to keep data in datasets as much as possible, that is really the point of datasets, and having a large and complex data processing language such as Base SAS to be able to work with the data.&amp;nbsp; Macro has none of that and is just a text replacement tool.&amp;nbsp; As I can't see any of the code really, or what most of the macro variables resolve to its hard to say, but create a dataset:&lt;BR /&gt;PARAM RES&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can simply call symputx(param,res,'g') from a datastep, real easy.&amp;nbsp; Or just merge the dataset onto your data and avoid the whole macro part at all - remember its only useful for generating Base SAS code, if you can do it in Base SAS, no need to use macro.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2017 15:24:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Declaring-multiple-global-macro-variables-within-a-macro-with/m-p/414865#M101689</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-20T15:24:27Z</dc:date>
    </item>
    <item>
      <title>Re: Declaring multiple global macro variables within a %macro with proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Declaring-multiple-global-macro-variables-within-a-macro-with/m-p/414868#M101690</link>
      <description>&lt;P&gt;Have your macro generate a %GLOBAL statement, before the related PROC SQL executes.&amp;nbsp; (PROC SQL can populate global variables, but it cannot create global variables when used inside of a macro.)&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%global Coeff_%scan(&amp;amp;INPUTS_EF.,&amp;amp;i.);&lt;/P&gt;
&lt;P&gt;%global Slope_%scan(&amp;amp;INPUTS_EF.&amp;amp;i.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are a few places to insert such statements, but they'll work just fine as long as they precede the SQL INTO : that populates the variable.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2017 15:29:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Declaring-multiple-global-macro-variables-within-a-macro-with/m-p/414868#M101690</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-11-20T15:29:02Z</dc:date>
    </item>
  </channel>
</rss>

