<?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: Executing Macro Functions from Macro Variables. Impossible? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/244882#M45676</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please check if following logic is helpful:-&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let TVAR = Y;
%let col1 = ,3 as c;
%let col2 = ,4 as d;
%let col3 = ,5 as e;


%macro ttestm;
	%let i = 1;
    Data Test; A = 5; run;
    proc sql;
        create table Test2 as
        select
        1 as A
        ,2 as B
		%do %while (&amp;amp;i &amp;lt;= 3);
		
			%if &amp;amp;i = 3 %then %let TVAR = N;

			%if &amp;amp;TVAR = Y %then 
			  &amp;amp;&amp;amp;col&amp;amp;i.;	
		%let i = %eval(&amp;amp;i + 1);
		%end;


        from Test

    ;quit;
%mend;
%ttestm;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 21 Jan 2016 06:58:37 GMT</pubDate>
    <dc:creator>ad123123</dc:creator>
    <dc:date>2016-01-21T06:58:37Z</dc:date>
    <item>
      <title>Executing Macro Functions from Macro Variables. Impossible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/244865#M45666</link>
      <description>&lt;P&gt;I have an SQL statement in SAS which generates many variables from a large dataset. In some cases, I only want some of the variables to generate. I could easily put %IF %THEN&amp;nbsp;conditions around each line / blocks of lines inside the&amp;nbsp;macro, However, I was hoping to make my code less messy by having the %IF %THEN inside a macro variable&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;AA.   ,sum(debt) as debt        &amp;amp;BB.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;instead of&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%IF &amp;amp;TVAR. = Y %THEN %DO;     ,sum(debt) as debt     %end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I try to run such code, I get aSyntax &amp;nbsp;error:&lt;/P&gt;&lt;PRE&gt;NOTE: Line generated by the macro variable "AA".
36          %if &amp;amp;TVAR. = Y %then %do;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example of the code that should work but doesn't. Is SAS simply unable to resolve %IF %THEN macro functions from Macro varibales?&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let TVAR = Y;
%let AA = %nrstr(%if &amp;amp;TVAR. = Y %then %do;);
%let BB = %nrstr(%end;);
%put &amp;amp;AA.;

%macro ttestm;
    Data Test; A = 5; run;
    proc sql;
        create table Test2 as
        select
        1 as A
        ,2 as B
        &amp;amp;AA. ,3 as C &amp;amp;BB.
        from Test
    ;quit;
%mend;
%ttestm;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are workarounds I can create but i'd rather have &amp;amp;AA. instead of long %IF &amp;amp;THENs all over the place.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tomek&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to add that the above code is an example. In reality i have code like:&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;,sum(case when debt_age is between 0 and 3 then debt else 0 end) as Debt3m
,max(write_off date) as latest_wod
,sum(case when payment &amp;gt; 0 and DOCTYPE = 'AR' then BILL else 0 end) as latest_payment&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, this is example code, but when you have tens of these types of variables and you need some to run always, and others to only run sometimes, I wanted neat code. However, It seems like SAS simply can't execute macro code from a variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 14:55:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/244865#M45666</guid>
      <dc:creator>TomekO</dc:creator>
      <dc:date>2016-01-21T14:55:55Z</dc:date>
    </item>
    <item>
      <title>Re: Executing Macro Functions from Macro Variables. Impossible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/244869#M45667</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use proc sql case expression. Here is a link to modify you code:-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/a002473682.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/a002473682.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please try following code:-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let TVAR='Y';&lt;BR /&gt;%put &amp;amp;TVAR.;&lt;BR /&gt;%macro ttestm;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data Test;&lt;BR /&gt;A = 5;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table test2 as&lt;BR /&gt;select 1 as A,&lt;BR /&gt;2 as B,&lt;BR /&gt;case&lt;BR /&gt;when &amp;amp;TVAR. = 'Y' then 50&lt;BR /&gt;else 100&lt;BR /&gt;end as C&lt;BR /&gt;from test;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%ttestm;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope it help you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;ABD&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 05:22:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/244869#M45667</guid>
      <dc:creator>ad123123</dc:creator>
      <dc:date>2016-01-21T05:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: Executing Macro Functions from Macro Variables. Impossible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/244870#M45668</link>
      <description>&lt;P&gt;That isn't exactly what I'm looking for. My example code makes my issue seem simpler than it is.&lt;BR /&gt;&lt;BR /&gt;I have complex sums with case whens inside loops which create hundreds of variables.&lt;BR /&gt;&lt;BR /&gt;This is why adding macro code around each of these would be best and simples, as opposed to incorporating an overlaying case when. It'd be better to just have the full %IF %THEN code instead.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 05:56:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/244870#M45668</guid>
      <dc:creator>TomekO</dc:creator>
      <dc:date>2016-01-21T05:56:54Z</dc:date>
    </item>
    <item>
      <title>Re: Executing Macro Functions from Macro Variables. Impossible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/244872#M45669</link>
      <description>&lt;P&gt;(Maybe you need put&amp;nbsp;%unquote() around it :&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 ttestm;
    Data Test; A = 5; run;
    proc sql;
        create table Test2 as
        select
        1 as A
        ,2 as B
       &lt;SPAN&gt;%unquote(&lt;/SPAN&gt; &amp;amp;AA. ) ,3 as C  &lt;SPAN&gt;%unquote(&lt;/SPAN&gt;&amp;amp;BB.)
        from Test
    ;quit;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And or you could use IFC()&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let TVAR = Y;
%let AA = %sysfunc(ifc(&amp;amp;TVAR. = Y ,%str(,sum%(debt%) as debt) , ));
%put %unquote(&amp;amp;AA.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Jan 2016 06:05:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/244872#M45669</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-01-21T06:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: Executing Macro Functions from Macro Variables. Impossible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/244873#M45670</link>
      <description>&lt;P&gt;Already tried that. The Error cahnges to:&lt;BR /&gt;&lt;BR /&gt;ERROR: The %IF statement is not valid in open code.&lt;BR /&gt;ERROR: The %END statement is not valid in open code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As for the other suggestion, that&amp;nbsp;would require me to change a lot of code so not ideal for me.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 06:09:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/244873#M45670</guid>
      <dc:creator>TomekO</dc:creator>
      <dc:date>2016-01-21T06:09:30Z</dc:date>
    </item>
    <item>
      <title>Re: Executing Macro Functions from Macro Variables. Impossible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/244878#M45674</link>
      <description>&lt;P&gt;That just says you have a %if and %end statement outside of a macro definition. Conditions and %do work only within a macro, not in open code.&lt;/P&gt;
&lt;P&gt;As %... keywords are interpreted by the macro engine immediately, you cannot use them to build a macro variable outside of the context of a macro definition.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 06:45:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/244878#M45674</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-01-21T06:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: Executing Macro Functions from Macro Variables. Impossible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/244880#M45675</link>
      <description>&lt;P&gt;Another question: why, in $DEITY's name, are you doing that? Putting the %if statement into a macro variable that is then used within a macro to dynamically create a macro statement is a clear attempt at winning the SAS obfuscated code contest.&lt;/P&gt;
&lt;P&gt;Rather follow the KISS principle, and write the statement where it shall be executed.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 06:49:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/244880#M45675</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-01-21T06:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: Executing Macro Functions from Macro Variables. Impossible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/244882#M45676</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please check if following logic is helpful:-&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let TVAR = Y;
%let col1 = ,3 as c;
%let col2 = ,4 as d;
%let col3 = ,5 as e;


%macro ttestm;
	%let i = 1;
    Data Test; A = 5; run;
    proc sql;
        create table Test2 as
        select
        1 as A
        ,2 as B
		%do %while (&amp;amp;i &amp;lt;= 3);
		
			%if &amp;amp;i = 3 %then %let TVAR = N;

			%if &amp;amp;TVAR = Y %then 
			  &amp;amp;&amp;amp;col&amp;amp;i.;	
		%let i = %eval(&amp;amp;i + 1);
		%end;


        from Test

    ;quit;
%mend;
%ttestm;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Jan 2016 06:58:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/244882#M45676</guid>
      <dc:creator>ad123123</dc:creator>
      <dc:date>2016-01-21T06:58:37Z</dc:date>
    </item>
    <item>
      <title>Re: Executing Macro Functions from Macro Variables. Impossible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/244913#M45686</link>
      <description>&lt;P&gt;Can you post test data in the form of a datastep and required output. &amp;nbsp;I don't see why you would need code like that to do this, base SAS and arrays should be sufficient. &amp;nbsp;Also, why do you want a wide table, coding using a long table is far easier, and simpler to code/process.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 09:55:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/244913#M45686</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-01-21T09:55:31Z</dc:date>
    </item>
    <item>
      <title>Re: Executing Macro Functions from Macro Variables. Impossible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/245183#M45722</link>
      <description>&lt;P&gt;You are making things difficult by trying to use a macro variable containing %IF/%THEN.&amp;nbsp; Instead, define a macro for each variable that is optional.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro debt (use=Y);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; %if &amp;amp;use=Y %then %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , sum(debt) as debt&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;
&lt;P&gt;%mend debt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then in your SELECT statement, you could add any of these:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%debt&lt;/P&gt;
&lt;P&gt;%debt (use=Y)&lt;/P&gt;
&lt;P&gt;%debt (use=N)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You just need to define a macro instead of a macro variable, and it's easy to read the code if you name the macro after the variable that it creates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 14:18:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/245183#M45722</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-01-21T14:18:03Z</dc:date>
    </item>
    <item>
      <title>Re: Executing Macro Functions from Macro Variables. Impossible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/245197#M45724</link>
      <description>&lt;P&gt;I need to add that the above code is an example. In reality i have code like:&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;,sum(case when debt_age is between 0 and 3 then debt else 0 end) as Debt3m
,max(write_off date) as latest_wod
,sum(case when payment &amp;gt; 0 and DOCTYPE = 'AR' then BILL else 0 end) as latest_payment&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, this is example code, but when you have tens of these types of variables and you need some to run always, and others to only run sometimes, I wanted neat code. However, It seems like SAS simply can't execute macro code from a variable.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 14:55:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/245197#M45724</guid>
      <dc:creator>TomekO</dc:creator>
      <dc:date>2016-01-21T14:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: Executing Macro Functions from Macro Variables. Impossible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/245207#M45726</link>
      <description>&lt;P&gt;Can I ask, why do these sometimes get done and sometimes not? &amp;nbsp;Identify what you need, and what cases you don't need certain things, and have processes for each.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 15:33:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/245207#M45726</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-01-21T15:33:00Z</dc:date>
    </item>
    <item>
      <title>Re: Executing Macro Functions from Macro Variables. Impossible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/245222#M45730</link>
      <description>&lt;P&gt;To make things easier, I'd use a data step and call execute to build the SQL or whatever you need to do. Once the basic problems of building program code with call execute are mastered, you can then use all the tools of the data step to automate the building of the code, using a control data set.&lt;/P&gt;
&lt;P&gt;This will take a lot of work in the beginning, but later on you only need to maintain your control data set.&lt;/P&gt;
&lt;P&gt;Keep in mind that the macro language as such is meant to automate other forms of SAS code. Using it to automate itself will end up being very tricky.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 16:37:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/245222#M45730</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-01-21T16:37:58Z</dc:date>
    </item>
    <item>
      <title>Re: Executing Macro Functions from Macro Variables. Impossible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/245231#M45735</link>
      <description>&lt;P&gt;Having read this question for a third time, I'm still stumped.&amp;nbsp; Why is this code neat and easy to read:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;
        create &lt;SPAN class="token statement"&gt;table&lt;/SPAN&gt; Test2 as
        &lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt;
        &lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; as A
        &lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt; as B
        &amp;amp;AA. &lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;3&lt;/SPAN&gt; as C &amp;amp;BB.
        &lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; Test
    &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token procnames"&gt;quit&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yet this code isn't?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;
        create &lt;SPAN class="token statement"&gt;table&lt;/SPAN&gt; Test2 as
        &lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt;
        &lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; as A
        &lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt; as B
        &lt;SPAN class="token operator"&gt;%&lt;/SPAN&gt;AA &lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;3&lt;/SPAN&gt; as C %BB
        &lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; Test
    &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token procnames"&gt;quit&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or even better yet:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;
        create &lt;SPAN class="token statement"&gt;table&lt;/SPAN&gt; Test2 as
        &lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt;
        &lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; as A
        &lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt; as B
        &lt;SPAN class="token operator"&gt;%Debt3m&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;3&lt;/SPAN&gt; as C &lt;SPAN class="token operator"&gt;%latest_wod&lt;/SPAN&gt;
        &lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; Test
    &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token procnames"&gt;quit&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What am I missing?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 17:01:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/245231#M45735</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-01-21T17:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: Executing Macro Functions from Macro Variables. Impossible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/245355#M45771</link>
      <description>So I could use %AA to have the If then code instead of &amp;amp;AA.?</description>
      <pubDate>Fri, 22 Jan 2016 00:26:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/245355#M45771</guid>
      <dc:creator>TomekO</dc:creator>
      <dc:date>2016-01-22T00:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: Executing Macro Functions from Macro Variables. Impossible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/245356#M45772</link>
      <description>Certainly. Sometimes, I want to run all the statements, like when building a new predictive model so I can look at all available variables.&lt;BR /&gt;&lt;BR /&gt;Other times, I want to run only certain lines, the one's necessary for existing models. Perhaps different options later on too so several if and/or then statements. Would be nice to have them stored in a short macro variable, rather than having an IF then on all the lines.&lt;BR /&gt;&lt;BR /&gt;All this I wish to be based on a Macro variable at the start.</description>
      <pubDate>Fri, 22 Jan 2016 00:29:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/245356#M45772</guid>
      <dc:creator>TomekO</dc:creator>
      <dc:date>2016-01-22T00:29:40Z</dc:date>
    </item>
    <item>
      <title>Re: Executing Macro Functions from Macro Variables. Impossible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/245395#M45785</link>
      <description>&lt;P&gt;Then I would write a macro like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro insert_va(var,as,cond);
%if &amp;amp;cond = 1 %then %do;
, &amp;amp;var as &amp;amp;as
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can write the select part of your SQL as a succession of macro calls, using different conditions for different variable groups. Set the conditions as macro variables before the SQL, and the rest automates itself. And you avoid complex code.&lt;/P&gt;
&lt;P&gt;Another version of the macro might be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro insert_va(var,as,condcode);
%if &amp;amp;global_cond = all or &amp;amp;globalcode = &amp;amp;condcode %then %do
, &amp;amp;var as &amp;amp;as
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This lets you set a specific condition for each variable, and if &amp;amp;global_cond is set to &lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;all&lt;/FONT&gt;&lt;/STRONG&gt; (note no quotes), all variables are included.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 07:19:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executing-Macro-Functions-from-Macro-Variables-Impossible/m-p/245395#M45785</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-01-22T07:19:22Z</dc:date>
    </item>
  </channel>
</rss>

