<?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: Macro not working as expected in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-not-working-as-expected/m-p/330897#M74309</link>
    <description>&lt;P&gt;ALWAYS keepi in mind that the macro processor is a&amp;nbsp;&lt;STRONG&gt;&lt;U&gt;pre&lt;/U&gt;&lt;/STRONG&gt;&lt;U&gt;&lt;/U&gt;processor that does its work&amp;nbsp;&lt;U&gt;before&lt;/U&gt; the data step is even compiled. It cannot access data step variables, it can only create text to be included as code in the data step.&lt;/P&gt;
&lt;P&gt;So this might work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro check (sdt , edt ,dif);
if &amp;amp;sdt ne . and &amp;amp;edt ne . then do;
  &amp;amp;dif=&amp;amp;edt - &amp;amp;sdt;
end;
if &amp;amp;sdt ne . and &amp;amp;edt eq . then do;
  &amp;amp;dif= &amp;amp;sdt;
end;
if &amp;amp;sdt eq . and &amp;amp;edt ne . then do;
  &amp;amp;dif=&amp;amp;edt ;
end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The macro now creates data step conditions and actions, only the variable names are taken from the macro parameters.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Feb 2017 16:35:04 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-02-08T16:35:04Z</dc:date>
    <item>
      <title>Macro not working as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-not-working-as-expected/m-p/330888#M74306</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone please help me on below code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro check (sdt , edt ,dif);&lt;BR /&gt;%if &amp;amp;sdt ne . and &amp;amp;edt ne . %then %do;&lt;BR /&gt;&amp;amp;dif=&amp;amp;edt - &amp;amp;sdt;&lt;BR /&gt;%end;&lt;BR /&gt;%if &amp;amp;sdt ne . and &amp;amp;edt eq . %then %do;&lt;BR /&gt;&amp;amp;dif= &amp;amp;sdt;&lt;BR /&gt;%end;&lt;BR /&gt;%if &amp;amp;sdt eq . and &amp;amp;edt ne . %then %do;&lt;BR /&gt;&amp;amp;dif=&amp;amp;edt ;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;data x;&lt;BR /&gt;infile datalines missover;&lt;BR /&gt;input a b ;&lt;BR /&gt;datalines;&lt;BR /&gt;10200 10300&lt;BR /&gt;10300 .&lt;BR /&gt;. 10200&lt;BR /&gt;;&lt;BR /&gt;options mlogic;&lt;BR /&gt;data y;&lt;BR /&gt;set x;&lt;BR /&gt;%check(a , b ,new);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Issue i am getting with this code is that only first condition is getting true while as per data provided and macro, all three conditions should get true for either records.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am pasting below snippet from log.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;65 ;&lt;BR /&gt;66 options mlogic;&lt;BR /&gt;67 data y;&lt;BR /&gt;68 set x;&lt;BR /&gt;69 %check(a , b ,new);&lt;BR /&gt;MLOGIC(CHECK): Beginning execution.&lt;BR /&gt;MLOGIC(CHECK): Parameter SDT has value a&lt;BR /&gt;MLOGIC(CHECK): Parameter EDT has value b&lt;BR /&gt;MLOGIC(CHECK): Parameter DIF has value new&lt;BR /&gt;MLOGIC(CHECK): %IF condition &amp;amp;sdt ne . and &amp;amp;edt ne . is TRUE&lt;BR /&gt;MLOGIC(CHECK): %IF condition &amp;amp;sdt ne . and &amp;amp;edt eq . is FALSE&lt;BR /&gt;MLOGIC(CHECK): %IF condition &amp;amp;sdt eq . and &amp;amp;edt ne . is FALSE&lt;BR /&gt;MLOGIC(CHECK): Ending execution.&lt;BR /&gt;70 run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me to modify the macro in a way that all three condtions will be resolved.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rajesh&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 16:22:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-not-working-as-expected/m-p/330888#M74306</guid>
      <dc:creator>draroda</dc:creator>
      <dc:date>2017-02-08T16:22:31Z</dc:date>
    </item>
    <item>
      <title>Re: Macro not working as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-not-working-as-expected/m-p/330897#M74309</link>
      <description>&lt;P&gt;ALWAYS keepi in mind that the macro processor is a&amp;nbsp;&lt;STRONG&gt;&lt;U&gt;pre&lt;/U&gt;&lt;/STRONG&gt;&lt;U&gt;&lt;/U&gt;processor that does its work&amp;nbsp;&lt;U&gt;before&lt;/U&gt; the data step is even compiled. It cannot access data step variables, it can only create text to be included as code in the data step.&lt;/P&gt;
&lt;P&gt;So this might work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro check (sdt , edt ,dif);
if &amp;amp;sdt ne . and &amp;amp;edt ne . then do;
  &amp;amp;dif=&amp;amp;edt - &amp;amp;sdt;
end;
if &amp;amp;sdt ne . and &amp;amp;edt eq . then do;
  &amp;amp;dif= &amp;amp;sdt;
end;
if &amp;amp;sdt eq . and &amp;amp;edt ne . then do;
  &amp;amp;dif=&amp;amp;edt ;
end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The macro now creates data step conditions and actions, only the variable names are taken from the macro parameters.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 16:35:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-not-working-as-expected/m-p/330897#M74309</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-08T16:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: Macro not working as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-not-working-as-expected/m-p/330902#M74311</link>
      <description>&lt;P&gt;First explain what the code is supposed to do.&lt;/P&gt;
&lt;P&gt;Since you are placing the macro code inside a data step then show us what the generated data step should look like if the macro ran as expected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 16:39:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-not-working-as-expected/m-p/330902#M74311</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-02-08T16:39:19Z</dc:date>
    </item>
    <item>
      <title>Re: Macro not working as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-not-working-as-expected/m-p/330903#M74312</link>
      <description>Thanks.This works.</description>
      <pubDate>Wed, 08 Feb 2017 16:43:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-not-working-as-expected/m-p/330903#M74312</guid>
      <dc:creator>draroda</dc:creator>
      <dc:date>2017-02-08T16:43:45Z</dc:date>
    </item>
  </channel>
</rss>

