<?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: %if %then %else %str macro functions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-str-macro-functions/m-p/436947#M108744</link>
    <description>&lt;P&gt;Remember that to the macro processor&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;MRT=1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is always false since the strings are different in the first character. Plus one is three characters long and the other is only one character long.&lt;/P&gt;</description>
    <pubDate>Wed, 14 Feb 2018 01:01:33 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-02-14T01:01:33Z</dc:date>
    <item>
      <title>%if %then %else %str macro functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-str-macro-functions/m-p/436900#M108719</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to use the %str function to modify my code. Here it is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro predictor;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data new;&lt;/P&gt;&lt;P&gt;set old;&lt;/P&gt;&lt;P&gt;pred=1/(1+exp(-1*(Intercept+ (AGE_P*AGE)+(SEX_P*SEX)+(EDU_P*EDU)&lt;/P&gt;&lt;P&gt;%if MRT=1 %then %str(&lt;/P&gt;&lt;P&gt;+ (MRT_P1))));&lt;/P&gt;&lt;P&gt;);&lt;/P&gt;&lt;P&gt;%else %if MRT=2 %then %str(&lt;/P&gt;&lt;P&gt;+ (MRT_P2))));&lt;/P&gt;&lt;P&gt;);&lt;/P&gt;&lt;P&gt;%else %str(&lt;/P&gt;&lt;P&gt;)));&lt;/P&gt;&lt;P&gt;);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%mend predictor;&lt;/P&gt;&lt;P&gt;%predictor;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I plug what's in the string functions individually, it works, so I know it doesn't have anything to do with how I coded the content (i.e. missing parentheses/semicolons). I've also used this function before in similar contexts, and never had a problem.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm getting the dreaded "There is no matching %IF statement for the %ELSE...A dummy macro will be compiled," error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Emily&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 22:17:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-else-str-macro-functions/m-p/436900#M108719</guid>
      <dc:creator>Caetreviop543</dc:creator>
      <dc:date>2018-02-13T22:17:14Z</dc:date>
    </item>
    <item>
      <title>Re: %if %then %else %str macro functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-str-macro-functions/m-p/436928#M108729</link>
      <description>&lt;P&gt;Macro language doesn't do what you are trying to make it do.&amp;nbsp; Macro language does not examine the contents of a DATA step variable in order to change the resulting SAS statements.&amp;nbsp; Macro language can only change the statements that go into a DATA step, before actually examining the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All is not lost.&amp;nbsp; You can fairly easily convert the formula to escape the need for macro language.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if mrt=1 then temp=mrt_p1;&lt;/P&gt;
&lt;P&gt;else if mrt=2 then temp=mrt_p2;&lt;/P&gt;
&lt;P&gt;else temp=0;&lt;/P&gt;
&lt;P&gt;pred=1/(1+exp(-1*(Intercept+ (AGE_P*AGE)+(SEX_P*SEX)+(EDU_P*EDU) + (temp) )));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think I got the parentheses balanced, but you will need to test to be sure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you actually have many possible values that you might want to use, arrays might be a possibility.&amp;nbsp; But macro language just isn't built to do this job.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 23:37:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-else-str-macro-functions/m-p/436928#M108729</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-13T23:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: %if %then %else %str macro functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-str-macro-functions/m-p/436939#M108739</link>
      <description>&lt;P&gt;Thanks!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So you can't use macro functions when trying to modify variables in a data step? Is that correct? I've used %if %then %do statements and macro variables in data steps and not had any issues. I guess I've only used %if %then %str in a proc though.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regardless, your response was super helpful! Creating the temp variable resolved my issue with differences between the predicted values produced by SAS and by hand.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Emily&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2018 00:20:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-else-str-macro-functions/m-p/436939#M108739</guid>
      <dc:creator>Caetreviop543</dc:creator>
      <dc:date>2018-02-14T00:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: %if %then %else %str macro functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-str-macro-functions/m-p/436940#M108740</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In&lt;/P&gt;
&lt;PRE&gt;%if MRT=1 %then %str(
+ (MRT_P1)  )   ));
);          ^&lt;/PRE&gt;
&lt;P&gt;The ) indicated with the ^ matches the ( for the %str function. So you have two semicolons seen by the interpreter before the %else. So the interpreter using the first ; as the end of the %if /%then as a single instruction. then the other ); which&amp;nbsp;I assume is supposed to close the Pred= assignment is encountered, the %else. So there isn't an available %if.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And why are you using %str in the first place? I suspect an %if %then %do; &amp;lt;code&amp;gt; %end;%else %do; &amp;lt;code&amp;gt; %end; %else %do;&amp;lt;other code&amp;gt; %end;&amp;nbsp; and then close the assignments ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run your code with option mprint; and see what it is actually generating when you call that macro.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2018 00:28:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-else-str-macro-functions/m-p/436940#M108740</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-02-14T00:28:26Z</dc:date>
    </item>
    <item>
      <title>Re: %if %then %else %str macro functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-str-macro-functions/m-p/436947#M108744</link>
      <description>&lt;P&gt;Remember that to the macro processor&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;MRT=1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is always false since the strings are different in the first character. Plus one is three characters long and the other is only one character long.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2018 01:01:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-else-str-macro-functions/m-p/436947#M108744</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-02-14T01:01:33Z</dc:date>
    </item>
    <item>
      <title>Re: %if %then %else %str macro functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-str-macro-functions/m-p/436964#M108750</link>
      <description>&lt;P&gt;It sounds like you're getting the idea.&amp;nbsp; A good way to simplify these ideas is this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro language helps you construct the statements that become part of the program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once the program is constructed (whether using macro language or not), after that is when the program executes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might want to review programs you have written that utilize macro language, and look at the programs in that light.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2018 02:56:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-else-str-macro-functions/m-p/436964#M108750</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-14T02:56:19Z</dc:date>
    </item>
    <item>
      <title>Re: %if %then %else %str macro functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-str-macro-functions/m-p/437284#M108854</link>
      <description>&lt;P&gt;Ok. thanks for your response. I was using %str function because it was less code. I did eventually resort to %if %then %do %end, but I think Astounding's response is the most succinct/straightforward.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2018 19:21:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-else-str-macro-functions/m-p/437284#M108854</guid>
      <dc:creator>Caetreviop543</dc:creator>
      <dc:date>2018-02-14T19:21:07Z</dc:date>
    </item>
  </channel>
</rss>

