<?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: Resolution of macro variables in a datastep with if/then testing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500773#M133429</link>
    <description>&lt;P&gt;I need to see some sort of working example, there are too many open parts here.&amp;nbsp; For instance you have this:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;&lt;SPAN class="token macrostatement"&gt;%if&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;norm_check&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;0&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%then&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%do&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/LI-CODE&gt;
&lt;P&gt;This code does not work in open code, needs to be in a macro.&amp;nbsp; This is never defined:&lt;/P&gt;
&lt;PRE&gt;&amp;amp;var.&lt;/PRE&gt;
&lt;P&gt;A good idea is also to show the log, will show what things decode to, so to debug turn on:&lt;/P&gt;
&lt;PRE&gt;options mlogic mprint symbolgen;&lt;/PRE&gt;
&lt;P&gt;You will then see the resolved code in the log which will help you debug.&lt;/P&gt;</description>
    <pubDate>Tue, 02 Oct 2018 14:44:03 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-10-02T14:44:03Z</dc:date>
    <item>
      <title>Resolution of macro variables in a datastep with if/then testing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500752#M133423</link>
      <description>&lt;P&gt;I'm having trouble getting If/Then statements to work correctly with my macro variables inside a datastep. I'm writing a macro to handle two different cases: calculating stat tests with no transformation, and then calculating stat tests after a natural log transformation. If my data fails the test of normality, I log transform and test again. If it passes, I set my global flag, `log_flag`, to 1. I then want to test the status of this flag in data steps in order to correctly handle the transformed (or not) variables. In this case 'Log_flag' should be set to 0, but the program runs as if it were a 1.&amp;nbsp; I've tried variations of the following:&lt;/P&gt;&lt;PRE&gt;Data want;
set have;
if symget("log_flag")=1 then do;
if &amp;amp;log_flag. = 1 then do;
if resolve("log_flag")=1 then do;&lt;BR /&gt;%if &amp;amp;log_flag. = 1 %then %do; xxx; %end;
test=symget("log_flag");
if test=1 then do;
end&lt;/PRE&gt;&lt;P&gt;No matter what I try, the if/then statement is essentially ignored and all code following it is processed as if the if/then were true, even when it is false. I know that the `log_flag` is being correctly assigned a value of zero because the `%if` `%then` statements work and execute correctly in open code.&amp;nbsp; I'm just having trouble getting it to resolve correctly inside a datastep.&amp;nbsp; Also, when I set the "test" variable to the value of symget("log_flag"), the test variable appears in the dataset with the correct value (0 in this case).&amp;nbsp; The if/then statement just seems to always evaluate to true and I have no idea why.&lt;/P&gt;&lt;P&gt;Please let me know if there is any other information you need to help me figure this out. Thanks guys!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 14:23:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500752#M133423</guid>
      <dc:creator>KevinJChristie</dc:creator>
      <dc:date>2018-10-02T14:23:01Z</dc:date>
    </item>
    <item>
      <title>Re: Resolution of macro variables in a datastep with if/then testing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500759#M133424</link>
      <description>&lt;P&gt;Macro code is resolved&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;before&lt;/STRONG&gt;&lt;/U&gt; the datastep is compiled and executed.&amp;nbsp; Depending on what other code you have:&lt;/P&gt;
&lt;PRE&gt;%let log_flag=0;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt; if &amp;amp;log_flag. = 1 then do;&lt;BR /&gt;   a="abc";&lt;BR /&gt; end;&lt;BR /&gt; else do;&lt;BR /&gt;   a="def";&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Works fine, as when the datastep is compiled &amp;amp;log_flag gets replaced by 1 (or 0).&amp;nbsp; Note how do needs to have an associated end with semicolon.&amp;nbsp; Please provide full code of an example you see for better information.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 14:23:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500759#M133424</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-02T14:23:29Z</dc:date>
    </item>
    <item>
      <title>Re: Resolution of macro variables in a datastep with if/then testing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500760#M133425</link>
      <description>&lt;P&gt;symget() and resolve() return character values, and so the results should be tested as such.&lt;/P&gt;
&lt;P&gt;resolve() expects a text expression, not a macro variable name, so you need to use &amp;amp;log_flag there.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let log_flag=1;

Data _null_;
if symget("log_flag") = "1" then put "A";
if &amp;amp;log_flag. = 1 then put "B";
if resolve("&amp;amp;log_flag") = "1" then put "C";
test = symget("log_flag");
if test = "1" then put "D";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Oct 2018 14:24:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500760#M133425</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-02T14:24:33Z</dc:date>
    </item>
    <item>
      <title>Re: Resolution of macro variables in a datastep with if/then testing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500761#M133426</link>
      <description>&lt;P&gt;One of your suggestions is simplest but not foolproof:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;if &amp;amp;log_flag = 1 then do;&lt;/P&gt;
&lt;P&gt;....&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just to be sure you can handle values other than 1 or 0, I would suggest changing it to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;if "&amp;amp;log_flag" = "1" then do;&lt;/P&gt;
&lt;P&gt;....&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, it wouldn't hurt to add this statement before the DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;log_flag;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 14:24:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500761#M133426</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-10-02T14:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: Resolution of macro variables in a datastep with if/then testing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500767#M133427</link>
      <description>&lt;P&gt;There are some timing issues between data step and macro values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since your example code has so many unclosed DO / END blocks it is pretty hard to see what you may be trying or where the issue crops up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case the macro variable value is resolved at compile time and becomes part of the code for the data step and returns the expected result.&lt;/P&gt;
&lt;PRE&gt;%let log_flag=0;

Data _null_;
if &amp;amp;log_flag = 1 then put "Log_flag = 1";
else if &amp;amp;log_flag = 0 then put "Log_flag = 0";

run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so log_flag is always ne 1 for the duration of the step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you attempting to set Log_flag macro variable in the same data step? Generally that isn't going to work. And if so, there would be no reason for a macro variable at all. Since you did not show how or when you set the macro variable perhaps that is an issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your macro variable log_flag were equal to 0 then this line:&lt;/P&gt;
&lt;PRE&gt;%if &amp;amp;log_flag. = 1 %then %do; xxx; %end;&lt;/PRE&gt;
&lt;P&gt;would yield a data step error of "ERROR 180-322: Statement is not valid or it is used out of proper order."&amp;nbsp;&amp;nbsp;&amp;nbsp;and the step would not execute at all.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 14:36:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500767#M133427</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-02T14:36:51Z</dc:date>
    </item>
    <item>
      <title>Re: Resolution of macro variables in a datastep with if/then testing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500768#M133428</link>
      <description>&lt;P&gt;Ok, here is the exact code I'm running:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let log_flag=0;&lt;BR /&gt;/*unimportant code that works correctly here */&lt;BR /&gt;&lt;BR /&gt;%if &amp;amp;norm_check. &amp;gt; 0 %then %do;&lt;BR /&gt;/* natural log transformation&lt;BR /&gt;%let log_flag=1 */&lt;BR /&gt;%end;&lt;BR /&gt;&lt;BR /&gt;data outliersTable2;
set outliersTable;
where &amp;amp;var.&amp;gt;Upper_limit or &amp;amp;var.&amp;lt;lower_Limit;
if &amp;amp;log_flag.=1 then do;
&amp;amp;var.=exp(&amp;amp;var);
q1_2=exp(q1);
median_2=exp(median);
q3_2=exp(q3);
iqr=exp(iqr);
lower_limit=exp(lower_limit);
upper_limit=exp(upper_limit);
drop resp;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Log_flag is 0 because I'm using non-transformed data.&amp;nbsp; I've attached the table that shows that the variable "resp" gets dropped, and q1_2, median_2, and q3_2 all get created when they shouldn't.&amp;nbsp; Everything after the do in the final section of code is just to back transform the natural log data.&amp;nbsp; Funny thing is the Q1_2, Median_2, and Q3_2 variables all get created, but not populated.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 14:38:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500768#M133428</guid>
      <dc:creator>KevinJChristie</dc:creator>
      <dc:date>2018-10-02T14:38:11Z</dc:date>
    </item>
    <item>
      <title>Re: Resolution of macro variables in a datastep with if/then testing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500773#M133429</link>
      <description>&lt;P&gt;I need to see some sort of working example, there are too many open parts here.&amp;nbsp; For instance you have this:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;&lt;SPAN class="token macrostatement"&gt;%if&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;norm_check&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;0&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%then&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%do&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/LI-CODE&gt;
&lt;P&gt;This code does not work in open code, needs to be in a macro.&amp;nbsp; This is never defined:&lt;/P&gt;
&lt;PRE&gt;&amp;amp;var.&lt;/PRE&gt;
&lt;P&gt;A good idea is also to show the log, will show what things decode to, so to debug turn on:&lt;/P&gt;
&lt;PRE&gt;options mlogic mprint symbolgen;&lt;/PRE&gt;
&lt;P&gt;You will then see the resolved code in the log which will help you debug.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 14:44:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500773#M133429</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-02T14:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: Resolution of macro variables in a datastep with if/then testing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500780#M133430</link>
      <description>&lt;UL&gt;
&lt;LI&gt;SYMGET() will return a character variable.&lt;/LI&gt;
&lt;LI&gt;RESOLVE() will return a character variable, but it needs the &amp;amp; in the parameter.&lt;/LI&gt;
&lt;LI&gt;&amp;amp;log_flag will resolve as numeric&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;You need to treat them correctly depending on your reference method.&lt;/P&gt;
&lt;P&gt;Here's an example of testing each one independently and then you can test them together via nesting if desired.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;%let log_flag=1;
Data want;
set sashelp.class;
if symget("log_flag")='1' then do;
  put "Test #1 is True";
end;

if &amp;amp;log_flag. = 1 then do;
  put "Test #2 is True";
end;


if resolve("&amp;amp;log_flag")="1" then do;
  put "Test #3 is True";
end;

test=symget("log_flag");
if test='1' then do;
  put "Test #4 is True";
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/65069"&gt;@KevinJChristie&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I'm having trouble getting If/Then statements to work correctly with my macro variables inside a datastep. I'm writing a macro to handle two different cases: calculating stat tests with no transformation, and then calculating stat tests after a natural log transformation. If my data fails the test of normality, I log transform and test again. If it passes, I set my global flag, `log_flag`, to 1. I then want to test the status of this flag in data steps in order to correctly handle the transformed (or not) variables. In this case 'Log_flag' should be set to 0, but the program runs as if it were a 1.&amp;nbsp; I've tried variations of the following:&lt;/P&gt;
&lt;PRE&gt;Data want;
set have;
if symget("log_flag")=1 then do;
if &amp;amp;log_flag. = 1 then do;
if resolve("log_flag")=1 then do;&lt;BR /&gt;%if &amp;amp;log_flag. = 1 %then %do; xxx; %end;
test=symget("log_flag");
if test=1 then do;
end&lt;/PRE&gt;
&lt;P&gt;No matter what I try, the if/then statement is essentially ignored and all code following it is processed as if the if/then were true, even when it is false. I know that the `log_flag` is being correctly assigned a value of zero because the `%if` `%then` statements work and execute correctly in open code.&amp;nbsp; I'm just having trouble getting it to resolve correctly inside a datastep.&amp;nbsp; Also, when I set the "test" variable to the value of symget("log_flag"), the test variable appears in the dataset with the correct value (0 in this case).&amp;nbsp; The if/then statement just seems to always evaluate to true and I have no idea why.&lt;/P&gt;
&lt;P&gt;Please let me know if there is any other information you need to help me figure this out. Thanks &lt;STRIKE&gt;guys!&amp;nbsp;&lt;/STRIKE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;PS. Not a guy.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 14:51:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500780#M133430</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-02T14:51:21Z</dc:date>
    </item>
    <item>
      <title>Re: Resolution of macro variables in a datastep with if/then testing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500783#M133431</link>
      <description>&lt;P&gt;Thanks to everyone's replies so far.&amp;nbsp; Just to answer a few questions:&lt;/P&gt;&lt;P&gt;I never try to assign 'Log_Flag' in a data step, only in open code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;All code that I'm posting comes from within a macro.&amp;nbsp; From start to finish.&lt;/P&gt;&lt;P&gt;Below is a screen shot of my log where the variable resolves correctly in open code&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Pic1.JPG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/23710iCDB2406DAB9EE910/image-size/large?v=v2&amp;amp;px=999" role="button" title="Pic1.JPG" alt="Pic1.JPG" /&gt;&lt;/span&gt;s&lt;/P&gt;&lt;P&gt;All of my do/end statements are closed, and there are no errors being thrown there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My whole goal is just to check the value of this flag within a data step, and then either perform or skip certain actions.&amp;nbsp; The problem is it doesn't seem to be performing the logic check.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you think I missed your suggestion, or am still not trying something in the way that you think will work please let me know.&amp;nbsp; I'm trying to keep up with everyone that's posted so far.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 14:52:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500783#M133431</guid>
      <dc:creator>KevinJChristie</dc:creator>
      <dc:date>2018-10-02T14:52:20Z</dc:date>
    </item>
    <item>
      <title>Re: Resolution of macro variables in a datastep with if/then testing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500786#M133432</link>
      <description>&lt;P&gt;Any variable mentioned in a DATA step automatically gets created:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;if 5=4 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;name='Fred';&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The variable NAME is created (but not populated since 5 never equals 4).&amp;nbsp; That's normal behavior for a DATA step.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 14:54:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500786#M133432</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-10-02T14:54:11Z</dc:date>
    </item>
    <item>
      <title>Re: Resolution of macro variables in a datastep with if/then testing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500790#M133433</link>
      <description>&lt;P&gt;Thanks for your suggestion of making sure I'm treating the variables correctly based on reference method.&amp;nbsp; I just tried:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data outliersTable2;
set outliersTable;
where &amp;amp;var.&amp;gt;Upper_limit or &amp;amp;var.&amp;lt;lower_Limit;
if SYMGET("log_flag")="1" then do;
&amp;amp;var.=exp(&amp;amp;var);
q1_2=exp(q1);
median_2=exp(median);
q3_2=exp(q3);
iqr=exp(iqr);
lower_limit=exp(lower_limit);
upper_limit=exp(upper_limit);
drop resp;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And I still get a table with columns that shouldn't be there (I.e. Q1_2, Median_2, and Q3_2).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Pic2.JPG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/23712i95B9D8354A1E9971/image-size/large?v=v2&amp;amp;px=999" role="button" title="Pic2.JPG" alt="Pic2.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had tried each one of your tests as a solution to my problem, but the problem is they're ALWAYS evaluating to true.&amp;nbsp; I can't get them to evaluate to false for some reason.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 15:03:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500790#M133433</guid>
      <dc:creator>KevinJChristie</dc:creator>
      <dc:date>2018-10-02T15:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: Resolution of macro variables in a datastep with if/then testing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500793#M133434</link>
      <description>&lt;P&gt;Yeah, that makes sense because you're not using macro logic there, you're using data step logic so the variables will always exist.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're misunderstanding how the macro and data step processor work here. You need macro logic and obviously this needs to be in a a macro as well. I think in 9.4 M5 that may have changed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data outliersTable2;
set outliersTable;
where &amp;amp;var.&amp;gt;Upper_limit or &amp;amp;var.&amp;lt;lower_Limit;
%if &amp;amp;log_flag=1 %then %do;
&amp;amp;var.=exp(&amp;amp;var);
q1_2=exp(q1);
median_2=exp(median);
q3_2=exp(q3);
iqr=exp(iqr);
lower_limit=exp(lower_limit);
upper_limit=exp(upper_limit);
drop resp;
%end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Oct 2018 15:04:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500793#M133434</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-02T15:04:26Z</dc:date>
    </item>
    <item>
      <title>Re: Resolution of macro variables in a datastep with if/then testing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500802#M133435</link>
      <description>&lt;P&gt;A DATA step IF statement cannot control the creation of data step variables.&amp;nbsp; When the DATA step compiles, all data step variables referenced in the code are created in the program data vector.&amp;nbsp; The DATA step IF is not evaluated until the step executes.&amp;nbsp; So below sample code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let log_flag=0 ;
data want ;
  set sashelp.class (keep=name age);
  if &amp;amp;log_flag=1 then do ;
    age2=age**2 ;
  end ;
  put _all_ ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Will always create the variable AGE2.&amp;nbsp; Because the step that compiles is:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set sashelp.class (keep=name age);
  if 0=1 then do ;
    age2=age**2 ;
  end ;
  put _all_ ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Because 0=1 is false, the AGE2 assignment statement will never be executed.&amp;nbsp; But it is compiled.&amp;nbsp; And therefore AGE2 is created (with a missing value).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to control the generation of the DATA step assignment statements, that is the job of the macro language %IF.&amp;nbsp; It controls what SAS code is generated.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro try() ;&lt;BR /&gt;%local log_flag ;
%let log_flag=0 ;
data want ;
  set sashelp.class (keep=name age);
  %if &amp;amp;log_flag=1 %then %do ;
    age2=age**2 ;
  %end ;
  put _all_ ;
run ;
%mend try ;
options mprint ;
%try()&lt;/PRE&gt;
&lt;P&gt;With that code, the AGE2 assignment statement is never generated, so it is not part of the DATA step code that is compiled.&amp;nbsp; MPRINT shows the code generated by the macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;MPRINT(TRY):   data want ;
MPRINT(TRY):   set sashelp.class (keep=name age);
MPRINT(TRY):   put _all_ ;
MPRINT(TRY):   run ;
&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Oct 2018 15:13:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500802#M133435</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2018-10-02T15:13:07Z</dc:date>
    </item>
    <item>
      <title>Re: Resolution of macro variables in a datastep with if/then testing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500807#M133436</link>
      <description>&lt;P&gt;I could have sworn I tried using %if and %then in the data step with no success, but this finally worked for me.&amp;nbsp; Thank you Reeza.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 15:17:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolution-of-macro-variables-in-a-datastep-with-if-then-testing/m-p/500807#M133436</guid>
      <dc:creator>KevinJChristie</dc:creator>
      <dc:date>2018-10-02T15:17:34Z</dc:date>
    </item>
  </channel>
</rss>

