<?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 SAS 9.4 TS Level 1M2: Unexpected Behavior using %IF, %THEN, %DO in a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-9-4-TS-Level-1M2-Unexpected-Behavior-using-IF-THEN-DO-in-a/m-p/440914#M110233</link>
    <description>&lt;P&gt;Hi, I cannot for the life of me understand why my macro is acting this way.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Context: I am creating a macro to conditionally generate reports depending on the macro variable lReportNum.&amp;nbsp;Below is a snippet of my code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%if &amp;amp;lReptNum. in (1,2,3,4) %then &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;%do;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;[proc report.. more sas code...]&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For some strange reason, when opening a new SAS session and '%include'ing my macro to run it, I&amp;nbsp;&lt;STRONG&gt;always&amp;nbsp;&lt;/STRONG&gt;get the following result from the &lt;STRONG&gt;first run&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SYMBOLGEN: Macro variable LREPTNUM resolves to 1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;MLOGIC(PMREPORT_YOY): %IF condition &amp;amp;lReptNum. in (1,2,3,4) is FALSE&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't understand why my condition is giving me FALSE. Here's the strange part: when I %include my macro again and run it a second time, I get the following result:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SYMBOLGEN: Macro variable LREPTNUM resolves to 1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;MLOGIC(PMREPORT_YOY): %IF condition &amp;amp;lReptNum. in (1,3,5,7) is TRUE&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that this results &lt;U&gt;only if I %include my macro a second time.&lt;/U&gt; I am not sure why this is happening. Any insight or help would be appreciated.&lt;/P&gt;</description>
    <pubDate>Wed, 28 Feb 2018 15:21:04 GMT</pubDate>
    <dc:creator>cashsas</dc:creator>
    <dc:date>2018-02-28T15:21:04Z</dc:date>
    <item>
      <title>SAS 9.4 TS Level 1M2: Unexpected Behavior using %IF, %THEN, %DO in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-9-4-TS-Level-1M2-Unexpected-Behavior-using-IF-THEN-DO-in-a/m-p/440914#M110233</link>
      <description>&lt;P&gt;Hi, I cannot for the life of me understand why my macro is acting this way.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Context: I am creating a macro to conditionally generate reports depending on the macro variable lReportNum.&amp;nbsp;Below is a snippet of my code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%if &amp;amp;lReptNum. in (1,2,3,4) %then &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;%do;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;[proc report.. more sas code...]&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For some strange reason, when opening a new SAS session and '%include'ing my macro to run it, I&amp;nbsp;&lt;STRONG&gt;always&amp;nbsp;&lt;/STRONG&gt;get the following result from the &lt;STRONG&gt;first run&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SYMBOLGEN: Macro variable LREPTNUM resolves to 1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;MLOGIC(PMREPORT_YOY): %IF condition &amp;amp;lReptNum. in (1,2,3,4) is FALSE&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't understand why my condition is giving me FALSE. Here's the strange part: when I %include my macro again and run it a second time, I get the following result:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SYMBOLGEN: Macro variable LREPTNUM resolves to 1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;MLOGIC(PMREPORT_YOY): %IF condition &amp;amp;lReptNum. in (1,3,5,7) is TRUE&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that this results &lt;U&gt;only if I %include my macro a second time.&lt;/U&gt; I am not sure why this is happening. Any insight or help would be appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2018 15:21:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-9-4-TS-Level-1M2-Unexpected-Behavior-using-IF-THEN-DO-in-a/m-p/440914#M110233</guid>
      <dc:creator>cashsas</dc:creator>
      <dc:date>2018-02-28T15:21:04Z</dc:date>
    </item>
    <item>
      <title>Re: SAS 9.4 TS Level 1M2: Unexpected Behavior using %IF, %THEN, %DO in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-9-4-TS-Level-1M2-Unexpected-Behavior-using-IF-THEN-DO-in-a/m-p/440921#M110236</link>
      <description>&lt;P&gt;The IN operator is a recent addition to macro code.&amp;nbsp; As such you need to make sure that you have set system options properly if you want to use it.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p0pbehl7wj5sl4n1ov1ortnehtba.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p0pbehl7wj5sl4n1ov1ortnehtba.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect that your first attempt is changing this setting so that your second attempt then works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That said your syntax does not look correct. Here is example from page linked above.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %eval(a IN a b c d);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Why do you have the parentheses?&amp;nbsp; Also did you make sure to set the delimiter to comma instead of space?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2018 15:38:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-9-4-TS-Level-1M2-Unexpected-Behavior-using-IF-THEN-DO-in-a/m-p/440921#M110236</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-02-28T15:38:04Z</dc:date>
    </item>
    <item>
      <title>Re: SAS 9.4 TS Level 1M2: Unexpected Behavior using %IF, %THEN, %DO in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-9-4-TS-Level-1M2-Unexpected-Behavior-using-IF-THEN-DO-in-a/m-p/441218#M110334</link>
      <description>&lt;P&gt;Hi Tom, thanks for your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found the solution. I had already set the following system options properly&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;options&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;minoperator&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;mindelimiter=',';&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;but I had set them inside the macro that conditionally generates the report. I moved the above options code outside the macro, and my code worked on the first run.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just a follow-up question if you don't mind, do you know why setting the system options inside the macro caused my code to work on only the second time after %include'ing a second time?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Mar 2018 15:16:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-9-4-TS-Level-1M2-Unexpected-Behavior-using-IF-THEN-DO-in-a/m-p/441218#M110334</guid>
      <dc:creator>cashsas</dc:creator>
      <dc:date>2018-03-01T15:16:30Z</dc:date>
    </item>
    <item>
      <title>Re: SAS 9.4 TS Level 1M2: Unexpected Behavior using %IF, %THEN, %DO in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-9-4-TS-Level-1M2-Unexpected-Behavior-using-IF-THEN-DO-in-a/m-p/441315#M110384</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/196163"&gt;@cashsas&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi Tom, thanks for your reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I found the solution. I had already set the following system options properly&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;options&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;minoperator&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;mindelimiter=',';&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;but I had set them inside the macro that conditionally generates the report. I moved the above options code outside the macro, and my code worked on the first run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just a follow-up question if you don't mind, do you know why setting the system options inside the macro caused my code to work on only the second time after %include'ing a second time?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A guess without seeing the entire macro code would be that the options were set after the first use of the in operator. If the include file had multiple macros it might be the order they were called for use such that the macro with the options wasn't called before another macro that used the option. Just defining a macro with the options wouldn't set them until the macro was executed at least once.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Mar 2018 18:24:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-9-4-TS-Level-1M2-Unexpected-Behavior-using-IF-THEN-DO-in-a/m-p/441315#M110384</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-01T18:24:37Z</dc:date>
    </item>
    <item>
      <title>Re: SAS 9.4 TS Level 1M2: Unexpected Behavior using %IF, %THEN, %DO in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-9-4-TS-Level-1M2-Unexpected-Behavior-using-IF-THEN-DO-in-a/m-p/441320#M110385</link>
      <description>&lt;P&gt;When you set the options makes a difference.&lt;/P&gt;
&lt;P&gt;It is the setting when CALL the macro that makes the difference.&lt;/P&gt;
&lt;PRE&gt;120   %macro test ;
121     %if x in a b c %then %put found ; %else %put not found ;
122   %mend test;
123
124
125   options nominoperator;
126   %put %sysfunc(getoption(minoperator));
NOMINOPERATOR
127   %test;
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is
       required. The condition was: x in a b c
ERROR: The macro TEST will stop executing.
128
129   options minoperator;
130   %put %sysfunc(getoption(minoperator));
MINOPERATOR
131   %test;
not found&lt;/PRE&gt;
&lt;P&gt;Note that if you use the options on the %MACRO statement then your macro will not depend on the system option.&lt;/P&gt;
&lt;PRE&gt;156   %macro test / minoperator;
157     %if x in a b c %then %put found ; %else %put not found ;
158   %mend test;
159
160
161   options nominoperator;
162   %put %sysfunc(getoption(minoperator));
NOMINOPERATOR
163   %test;
not found
164
165   options minoperator;
166   %put %sysfunc(getoption(minoperator));
MINOPERATOR
167   %test;
not found
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Mar 2018 18:39:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-9-4-TS-Level-1M2-Unexpected-Behavior-using-IF-THEN-DO-in-a/m-p/441320#M110385</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-01T18:39:03Z</dc:date>
    </item>
  </channel>
</rss>

