<?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 If-then-do statement not working in macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-then-do-statement-not-working-in-macro/m-p/893926#M353131</link>
    <description>&lt;P&gt;I am trying to write a macro to replace certain variables if condition is satisfied but it returns the original data to me.&amp;nbsp; For example, for the data below, I want to make country=country2 and meal=meal2 if company="ABC" and source=2 (I want to make the second record to be (2 ABC Mary 12000 GERMANY GERMANT PIZZA PIZZA)&lt;/P&gt;&lt;P&gt;This is my dataset&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data test;
input source company $ employee $ country $ country2 $ meal $ meal2;
datalines;
1 ABC Smith 10000 USA USA  BURGER BURGER
2 ABC Mary 12000 USA GERMANY BURGER PIZZA
1 EFG Tim 11000 CANADA USE PIZZA PIZZA
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The macro function I tried to use to accomplish&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro finalize;
data final;set test;
%if company="ABC" and source=2 %then %do;
country=country2;
meal=meal2;
%end;
run;
%mend;
%finalize;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But it returns the original dataset without changing anything and there was no error, I still have (2 ABC Mary 12000 USA GERMANT BURGER PIZZA)&amp;nbsp;instead of my expected output of&amp;nbsp; (2 ABC Mary 12000 GERMANY GERMANT PIZZA PIZZA). Can someone please let me know what is the reason? Thanks&lt;/P&gt;</description>
    <pubDate>Tue, 12 Sep 2023 20:38:17 GMT</pubDate>
    <dc:creator>apeeape</dc:creator>
    <dc:date>2023-09-12T20:38:17Z</dc:date>
    <item>
      <title>If-then-do statement not working in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-do-statement-not-working-in-macro/m-p/893926#M353131</link>
      <description>&lt;P&gt;I am trying to write a macro to replace certain variables if condition is satisfied but it returns the original data to me.&amp;nbsp; For example, for the data below, I want to make country=country2 and meal=meal2 if company="ABC" and source=2 (I want to make the second record to be (2 ABC Mary 12000 GERMANY GERMANT PIZZA PIZZA)&lt;/P&gt;&lt;P&gt;This is my dataset&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data test;
input source company $ employee $ country $ country2 $ meal $ meal2;
datalines;
1 ABC Smith 10000 USA USA  BURGER BURGER
2 ABC Mary 12000 USA GERMANY BURGER PIZZA
1 EFG Tim 11000 CANADA USE PIZZA PIZZA
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The macro function I tried to use to accomplish&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro finalize;
data final;set test;
%if company="ABC" and source=2 %then %do;
country=country2;
meal=meal2;
%end;
run;
%mend;
%finalize;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But it returns the original dataset without changing anything and there was no error, I still have (2 ABC Mary 12000 USA GERMANT BURGER PIZZA)&amp;nbsp;instead of my expected output of&amp;nbsp; (2 ABC Mary 12000 GERMANY GERMANT PIZZA PIZZA). Can someone please let me know what is the reason? Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2023 20:38:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-do-statement-not-working-in-macro/m-p/893926#M353131</guid>
      <dc:creator>apeeape</dc:creator>
      <dc:date>2023-09-12T20:38:17Z</dc:date>
    </item>
    <item>
      <title>Re: If-then-do statement not working in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-do-statement-not-working-in-macro/m-p/893929#M353133</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro finalize;

data final;
set test;
if company="ABC" and source=2 then do;
country=country2;
meal=meal2;
end;
run;
%mend;


%finalize;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There's nothing in this logic requiring macro %if/%then. Use a standard if/then.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/380833"&gt;@apeeape&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to write a macro to replace certain variables if condition is satisfied but it returns the original data to me.&amp;nbsp; For example, for the data below, I want to make country=country2 and meal=meal2 if company="ABC" and source=2 (I want to make the second record to be (2 ABC Mary 12000 GERMANY GERMANT PIZZA PIZZA)&lt;/P&gt;
&lt;P&gt;This is my dataset&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data test;
input source company $ employee $ country $ country2 $ meal $ meal2;
datalines;
1 ABC Smith 10000 USA USA  BURGER BURGER
2 ABC Mary 12000 USA GERMANY BURGER PIZZA
1 EFG Tim 11000 CANADA USE PIZZA PIZZA
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The macro function I tried to use to accomplish&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;%macro finalize;
data final;set test;
%if company="ABC" and source=2 %then %do;
country=country2;
meal=meal2;
%end;
run;
%mend;
%finalize;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But it returns the original dataset without changing anything and there was no error, I still have (2 ABC Mary 12000 USA GERMANT BURGER PIZZA)&amp;nbsp;instead of my expected output of&amp;nbsp; (2 ABC Mary 12000 GERMANY GERMANT PIZZA PIZZA). Can someone please let me know what is the reason? Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2023 20:41:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-do-statement-not-working-in-macro/m-p/893929#M353133</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-09-12T20:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: If-then-do statement not working in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-do-statement-not-working-in-macro/m-p/893932#M353134</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if company="ABC" and source=2 %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%IF %THEN %DO works on macro variables. It cannot access values of data step variables, and so it cannot test to see if company="ABC"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF THEN DO works on data step variables and constants. It can test to see if the value of a data step variable is equal to something.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is also no obvious need for a macro here.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2023 20:47:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-do-statement-not-working-in-macro/m-p/893932#M353134</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-09-12T20:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: If-then-do statement not working in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-do-statement-not-working-in-macro/m-p/893934#M353136</link>
      <description>&lt;P&gt;Thanks a lot that works! I am very confused when using macro haha&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2023 20:47:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-do-statement-not-working-in-macro/m-p/893934#M353136</guid>
      <dc:creator>apeeape</dc:creator>
      <dc:date>2023-09-12T20:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: If-then-do statement not working in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-do-statement-not-working-in-macro/m-p/893935#M353137</link>
      <description>Thanks for the information! Lesson learned &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Tue, 12 Sep 2023 20:47:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-do-statement-not-working-in-macro/m-p/893935#M353137</guid>
      <dc:creator>apeeape</dc:creator>
      <dc:date>2023-09-12T20:47:41Z</dc:date>
    </item>
  </channel>
</rss>

