<?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 macro %if  condition %then action; in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-if-condition-then-action/m-p/64299#M13988</link>
    <description>Hi Guys,&lt;BR /&gt;
&lt;BR /&gt;
  I have a question regarding SAS macro %IF %Then Syntax;&lt;BR /&gt;
&lt;BR /&gt;
I know %If condition  %then action; works&lt;BR /&gt;
&lt;BR /&gt;
but once I have mutiple if within if/elseif,&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;do i have to have add %do; and %End; ?&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
I am converting access macro code into sas macro,&lt;BR /&gt;
so i prefer not to add the %do &amp;amp; %end  &lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
&lt;BR /&gt;
The following is my macro,&lt;BR /&gt;
&lt;BR /&gt;
and I have error &lt;BR /&gt;
&lt;BR /&gt;
&lt;I&gt;ERROR: There is no matching %IF statement for the %ELSE. A dummy macro will be compiled.&lt;/I&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%Macro PoolAdj(effdate= ,State= ,Lives= );&lt;BR /&gt;
%let PoolAdj = 1;&lt;BR /&gt;
&lt;BR /&gt;
%IF &amp;amp;effdate ^= "?" %then&lt;BR /&gt;
    %IF &amp;amp;state ^= "FL" And &amp;amp;state ^= "NY" %then&lt;BR /&gt;
&lt;BR /&gt;
        %IF &amp;amp;effdate &amp;gt; '06Jun2004' %then&lt;BR /&gt;
            %IF &amp;amp;lives &amp;lt; 10 %then&lt;BR /&gt;
                &amp;amp;PoolAdj = &amp;amp;PoolAdj * 1;&lt;BR /&gt;
            %else %if &amp;amp;lives &amp;lt; 500 %then&lt;BR /&gt;
                &amp;amp;PoolAdj = &amp;amp;PoolAdj * 0.95;&lt;BR /&gt;
            %else&lt;BR /&gt;
                &amp;amp;PoolAdj = &amp;amp;PoolAdj * 0.97;&lt;BR /&gt;
         ;&lt;BR /&gt;
            &lt;BR /&gt;
        %else %if &amp;amp;effdate &amp;gt; '09May2002' %then&lt;BR /&gt;
            %IF &amp;amp;lives &amp;lt; 10 %then&lt;BR /&gt;
                &amp;amp;PoolAdj = &amp;amp;PoolAdj * 1;&lt;BR /&gt;
            %else %if &amp;amp;lives &amp;lt; 500 %then&lt;BR /&gt;
                &amp;amp;PoolAdj = &amp;amp;PoolAdj * 0.95;&lt;BR /&gt;
            %else&lt;BR /&gt;
                &amp;amp;PoolAdj = &amp;amp;PoolAdj * 0.97;&lt;BR /&gt;
         ;    &lt;BR /&gt;
     ;&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%Mend PoolAdj;

Message was edited by: fortrichmond</description>
    <pubDate>Wed, 03 Dec 2008 22:04:00 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-12-03T22:04:00Z</dc:date>
    <item>
      <title>macro %if  condition %then action;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-if-condition-then-action/m-p/64299#M13988</link>
      <description>Hi Guys,&lt;BR /&gt;
&lt;BR /&gt;
  I have a question regarding SAS macro %IF %Then Syntax;&lt;BR /&gt;
&lt;BR /&gt;
I know %If condition  %then action; works&lt;BR /&gt;
&lt;BR /&gt;
but once I have mutiple if within if/elseif,&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;do i have to have add %do; and %End; ?&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
I am converting access macro code into sas macro,&lt;BR /&gt;
so i prefer not to add the %do &amp;amp; %end  &lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
&lt;BR /&gt;
The following is my macro,&lt;BR /&gt;
&lt;BR /&gt;
and I have error &lt;BR /&gt;
&lt;BR /&gt;
&lt;I&gt;ERROR: There is no matching %IF statement for the %ELSE. A dummy macro will be compiled.&lt;/I&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%Macro PoolAdj(effdate= ,State= ,Lives= );&lt;BR /&gt;
%let PoolAdj = 1;&lt;BR /&gt;
&lt;BR /&gt;
%IF &amp;amp;effdate ^= "?" %then&lt;BR /&gt;
    %IF &amp;amp;state ^= "FL" And &amp;amp;state ^= "NY" %then&lt;BR /&gt;
&lt;BR /&gt;
        %IF &amp;amp;effdate &amp;gt; '06Jun2004' %then&lt;BR /&gt;
            %IF &amp;amp;lives &amp;lt; 10 %then&lt;BR /&gt;
                &amp;amp;PoolAdj = &amp;amp;PoolAdj * 1;&lt;BR /&gt;
            %else %if &amp;amp;lives &amp;lt; 500 %then&lt;BR /&gt;
                &amp;amp;PoolAdj = &amp;amp;PoolAdj * 0.95;&lt;BR /&gt;
            %else&lt;BR /&gt;
                &amp;amp;PoolAdj = &amp;amp;PoolAdj * 0.97;&lt;BR /&gt;
         ;&lt;BR /&gt;
            &lt;BR /&gt;
        %else %if &amp;amp;effdate &amp;gt; '09May2002' %then&lt;BR /&gt;
            %IF &amp;amp;lives &amp;lt; 10 %then&lt;BR /&gt;
                &amp;amp;PoolAdj = &amp;amp;PoolAdj * 1;&lt;BR /&gt;
            %else %if &amp;amp;lives &amp;lt; 500 %then&lt;BR /&gt;
                &amp;amp;PoolAdj = &amp;amp;PoolAdj * 0.95;&lt;BR /&gt;
            %else&lt;BR /&gt;
                &amp;amp;PoolAdj = &amp;amp;PoolAdj * 0.97;&lt;BR /&gt;
         ;    &lt;BR /&gt;
     ;&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%Mend PoolAdj;

Message was edited by: fortrichmond</description>
      <pubDate>Wed, 03 Dec 2008 22:04:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-if-condition-then-action/m-p/64299#M13988</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-12-03T22:04:00Z</dc:date>
    </item>
    <item>
      <title>Re: macro %if  condition %then action;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-if-condition-then-action/m-p/64300#M13989</link>
      <description>Yes, multiple-statement logic within a defined %IF construct requires a %DO and a %END structure.&lt;BR /&gt;
&lt;BR /&gt;
Have a look at the SAS-hosted documentation on the MACRO language logic at the link below.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/59526/HTML/default/a001037922.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/59526/HTML/default/a001037922.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
SAS Support hosted prod documentation:&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/" target="_blank"&gt;http://support.sas.com/documentation/&lt;/A&gt;</description>
      <pubDate>Thu, 04 Dec 2008 02:27:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-if-condition-then-action/m-p/64300#M13989</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2008-12-04T02:27:16Z</dc:date>
    </item>
    <item>
      <title>Re: macro %if  condition %then action;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-if-condition-then-action/m-p/64301#M13990</link>
      <description>I think the only problem with this code is exactly what the error message expresses.&lt;BR /&gt;
There is no matching '%if' case for the '%else' case.&lt;BR /&gt;
&lt;BR /&gt;
.....&lt;BR /&gt;
%else&lt;BR /&gt;
&amp;amp;PoolAdj = &amp;amp;PoolAdj * 0.97; &lt;BR /&gt;
;&lt;BR /&gt;
%else %if &amp;amp;effdate &amp;gt; '09May2002' %then&lt;BR /&gt;
....&lt;BR /&gt;
&lt;BR /&gt;
Formulate it this way and it should work:&lt;BR /&gt;
.....&lt;BR /&gt;
%else&lt;BR /&gt;
&amp;amp;PoolAdj = &amp;amp;PoolAdj * 0.97; &lt;BR /&gt;
;&lt;BR /&gt;
%if &amp;amp;effdate &amp;gt; '09May2002' %then&lt;BR /&gt;
....&lt;BR /&gt;
&lt;BR /&gt;
As all conditions are on the same level you will have to check that the %if statements are exclusive to each other or your logic will be flawed.&lt;BR /&gt;
&lt;BR /&gt;
From a programming perspective I consider a %do...%end structure as easier to read and maintain.&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Thu, 04 Dec 2008 09:07:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-if-condition-then-action/m-p/64301#M13990</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2008-12-04T09:07:41Z</dc:date>
    </item>
  </channel>
</rss>

