<?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: SAS macro %if %then %else problem in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-macro-if-then-else-problem/m-p/479787#M31129</link>
    <description>&lt;P&gt;&lt;A href="http://support.sas.com/kb/24/170.html" target="_blank"&gt;http://support.sas.com/kb/24/170.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Jul 2018 03:46:13 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-07-20T03:46:13Z</dc:date>
    <item>
      <title>SAS macro %if %then %else problem</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-macro-if-then-else-problem/m-p/479766#M31126</link>
      <description>&lt;P&gt;I am writing a macro to create a 2x2 table and calculate sensitivity/specificity/ etc. A part of the macro is not working well, and I have no idea why. The code does not have any error message, but seems it only import the set &amp;amp;data, but not do anything about the %if %then result. Here is part of the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO tabulate(data, target, comp);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;/* ................datalines........................ */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; data data1 (replace=yes);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set &amp;amp;data;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;%if&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;"&amp;amp;comp._&amp;amp;target._result"="Positive"&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;"V_&amp;amp;target._result"="Positive" %then&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;result="TP";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;%else&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;%if&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;"&amp;amp;comp._&amp;amp;target._result"="Positive"&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;"V_&amp;amp;target._result"="Negative" %then&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;result="FN";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;%else&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;%if&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;"&amp;amp;comp._&amp;amp;target._result"="Negative"&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;"V_&amp;amp;target._result"="Positive" %then&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;result="FP";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;%else&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;%if&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;"&amp;amp;comp._&amp;amp;target._result"="Negative"&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;"V_&amp;amp;target._result"="Negative" %then&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;result="TN";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*................ more data ............*/&lt;/P&gt;&lt;P&gt;%MEND;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also tried to use %then %put result = "TP", still not working. This part of the code should give me a new column with name "result", and have "TP" "FN" "FP" "TN" in the column.&lt;/P&gt;&lt;P&gt;I can run this in the main program, but when I put this into a macro, it does not work.&lt;/P&gt;&lt;P&gt;Thank you if you can give me some advice.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jul 2018 00:34:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-macro-if-then-else-problem/m-p/479766#M31126</guid>
      <dc:creator>y_fu</dc:creator>
      <dc:date>2018-07-20T00:34:36Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro %if %then %else problem</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-macro-if-then-else-problem/m-p/479768#M31127</link>
      <description>&lt;P&gt;DATA steps can't execute macro statements.&amp;nbsp; Just get rid of all the percent signs and you should be fine.&amp;nbsp; (Leave the ampersands in place, only the percent signs need to go.)&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jul 2018 00:47:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-macro-if-then-else-problem/m-p/479768#M31127</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-20T00:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro %if %then %else problem</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-macro-if-then-else-problem/m-p/479772#M31128</link>
      <description>&lt;P&gt;Macro code is scanned &amp;amp; executed before data step code is scanned &amp;amp; executed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It might be simpler to maintain if you separate the macro &amp;amp; data step code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO tabulate(data, target, comp);

  /* ................datalines........................ */

%local result;
%if  &amp;amp;comp._&amp;amp;target._result=Positive and V_&amp;amp;target._result=Positive %then %let result=TP;
%else %if &amp;amp;comp._&amp;amp;target._result=Positive and V_&amp;amp;target._result=Negative %then result=FN;
%else %if &amp;amp;comp._&amp;amp;target._result=Negative and V_&amp;amp;target._result=Positive %then result=FP;
%else %if &amp;amp;comp._&amp;amp;target._result=Negative and V_&amp;amp;target._result=Negative %then result=TN;

  data data1 (replace=yes);
          set &amp;amp;data;
          result="&amp;amp;result";
  run;
 
/*................ more data ............*/

%MEND;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jul 2018 01:59:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-macro-if-then-else-problem/m-p/479772#M31128</guid>
      <dc:creator>AndrewHowell</dc:creator>
      <dc:date>2018-07-20T01:59:38Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro %if %then %else problem</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-macro-if-then-else-problem/m-p/479787#M31129</link>
      <description>&lt;P&gt;&lt;A href="http://support.sas.com/kb/24/170.html" target="_blank"&gt;http://support.sas.com/kb/24/170.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jul 2018 03:46:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-macro-if-then-else-problem/m-p/479787#M31129</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-20T03:46:13Z</dc:date>
    </item>
  </channel>
</rss>

