<?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 Statement, why cannot I generate a second variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278712#M56083</link>
    <description>Thank you very much!!!</description>
    <pubDate>Mon, 20 Jun 2016 15:25:59 GMT</pubDate>
    <dc:creator>Bal23</dc:creator>
    <dc:date>2016-06-20T15:25:59Z</dc:date>
    <item>
      <title>sas macro %IF-%THEN/%ELSE Statement, why cannot I generate a second variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278513#M56030</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mactem2(tem );
%if &amp;amp;tem ne "low" %then %do;
data hem;
set chicken;
importance2=importance+100;
run;
%end;
%else if &amp;amp;tem ="low" then %do;
importance3=importance+30;
run;
%end;
%mend mactem2;&lt;BR /&gt;there is no error message. But I can only find variable importance2 but not importance3. &lt;BR /&gt;any advice to modify my code so I can generate the variable importance3? Thanks
mactem2(low);
mactem2(mid);
mactem2(war);
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 19 Jun 2016 19:34:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278513#M56030</guid>
      <dc:creator>Bal23</dc:creator>
      <dc:date>2016-06-19T19:34:33Z</dc:date>
    </item>
    <item>
      <title>Re: sas macro %IF-%THEN/%ELSE Statement, why cannot I generate a second variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278515#M56031</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mactem2(tem );
%if &amp;amp;tem ne low %then %do;
data hem;
set chicken;
importance2=importance+100;
run;
%end;
%else if &amp;amp;tem = low %then %do;&lt;BR /&gt;data hem;
importance3=importance+30;
run;
%end;
%mend mactem2;
mactem2(low);
mactem2(mid);
mactem2(war);
&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 19 Jun 2016 20:17:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278515#M56031</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2016-06-19T20:17:34Z</dc:date>
    </item>
    <item>
      <title>Re: sas macro %IF-%THEN/%ELSE Statement, why cannot I generate a second variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278517#M56032</link>
      <description>&lt;P&gt;Importance3 is after the run statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It doesn't end up in a data step so it never gets created.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the data step regardless you don't need a macro %if then. Also all the if/then/do need a % symbol in front of them. You also need a % in front of your macro call.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this get you what you want.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mactem2(tem );

data hem;
set chicken;&lt;BR /&gt;&lt;BR /&gt;if "&amp;amp;tem" ne "low" then 
importance2=importance+100;

else if "&amp;amp;tem" ="low" then
importance3=importance+30;
run;

%mend mactem2;&lt;BR /&gt;
%mactem2(low);
%mactem2(mid);
%mactem2(war);
&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jun 2016 20:10:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278517#M56032</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-19T20:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: sas macro %IF-%THEN/%ELSE Statement, why cannot I generate a second variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278518#M56033</link>
      <description>&lt;P&gt;Also, since your dataset name is not unique when you run the three macro calls one after each other only the final one exists, each one overwrites the previous dataset (hem).&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jun 2016 20:12:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278518#M56033</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-19T20:12:39Z</dc:date>
    </item>
    <item>
      <title>Re: sas macro %IF-%THEN/%ELSE Statement, why cannot I generate a second variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278519#M56034</link>
      <description>&lt;P&gt;Thank you very much.&lt;/P&gt;&lt;P&gt;But I am required to use macro %IF-%THEN/%ELSE Statement,&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jun 2016 20:14:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278519#M56034</guid>
      <dc:creator>Bal23</dc:creator>
      <dc:date>2016-06-19T20:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: sas macro %IF-%THEN/%ELSE Statement, why cannot I generate a second variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278520#M56035</link>
      <description>&lt;P&gt;Ok. Well the structure is identical. Replace my if statements with macro if then statements.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jun 2016 20:23:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278520#M56035</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-19T20:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: sas macro %IF-%THEN/%ELSE Statement, why cannot I generate a second variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278521#M56036</link>
      <description>&lt;P&gt;%macro mactem2 (tem );&lt;/P&gt;&lt;P&gt;data hem;&lt;/P&gt;&lt;P&gt;set chicken;&lt;/P&gt;&lt;P&gt;%if &amp;amp;tem ne "low" %then %do;&lt;/P&gt;&lt;P&gt;importanc2=importance+100;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%else %if &amp;amp;tem = "low" %then %do;&lt;/P&gt;&lt;P&gt;importance3= importance+30;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend mactem2;&lt;/P&gt;&lt;P&gt;%mactem2(low);&lt;/P&gt;&lt;P&gt;%mactem2(mid);&lt;/P&gt;&lt;P&gt;%mactem2(war);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;still I cannot create the variable importance3. Check the log file, it always believe the statment is True, that is, it believe the statement is true, that is, %if condition &amp;amp;tem ne "low" is True&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also tried to replace &amp;amp;tem with tem, as tem is my variable&lt;/P&gt;&lt;P&gt;ANy advice?&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jun 2016 20:36:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278521#M56036</guid>
      <dc:creator>Bal23</dc:creator>
      <dc:date>2016-06-19T20:36:19Z</dc:date>
    </item>
    <item>
      <title>Re: sas macro %IF-%THEN/%ELSE Statement, why cannot I generate a second variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278525#M56038</link>
      <description>&lt;P&gt;Your second if/then/do is missing an END?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have an extra END outside of the run?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are there variables in your dataset called low/mid/var? If not either enclose all strings in quotes or none in your comparison.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if &amp;amp;item = low %then ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Again, if you call them one after each other you won't see interim datasets. I suggest adding a proc print after run but before mend to see the data results. You can print just a few observations.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jun 2016 21:04:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278525#M56038</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-19T21:04:49Z</dc:date>
    </item>
    <item>
      <title>Re: sas macro %IF-%THEN/%ELSE Statement, why cannot I generate a second variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278533#M56040</link>
      <description>&lt;P&gt;Quick tip, If you indent your code you'll see a lot of these issues right away.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jun 2016 21:35:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278533#M56040</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-19T21:35:22Z</dc:date>
    </item>
    <item>
      <title>Re: sas macro %IF-%THEN/%ELSE Statement, why cannot I generate a second variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278589#M56057</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/40773"&gt;@Bal23&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;%macro mactem2 (tem );&lt;/P&gt;
&lt;P&gt;data hem;&lt;/P&gt;
&lt;P&gt;set chicken;&lt;/P&gt;
&lt;P&gt;%if &amp;amp;tem ne "low" %then %do;&lt;/P&gt;
&lt;P&gt;importanc2=importance+100;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;%else %if &amp;amp;tem = "low" %then %do;&lt;/P&gt;
&lt;P&gt;importance3= importance+30;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;%mend mactem2;&lt;/P&gt;
&lt;P&gt;%mactem2(low);&lt;/P&gt;
&lt;P&gt;%mactem2(mid);&lt;/P&gt;
&lt;P&gt;%mactem2(war);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;still I cannot create the variable importance3. Check the log file, it always believe the statment is True, that is, it believe the statement is true, that is, %if condition &amp;amp;tem ne "low" is True&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also tried to replace &amp;amp;tem with tem, as tem is my variable&lt;/P&gt;
&lt;P&gt;ANy advice?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;tem ne "low" %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%else %if &amp;amp;tem = "low" %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;are the culprits.&lt;/P&gt;
&lt;P&gt;You once again missed the quotes.&lt;/P&gt;
&lt;P&gt;It must look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if "&amp;amp;tem" ne "low" %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%else %if "&amp;amp;tem" = "low" %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2016 07:36:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278589#M56057</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-06-20T07:36:01Z</dc:date>
    </item>
    <item>
      <title>Re: sas macro %IF-%THEN/%ELSE Statement, why cannot I generate a second variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278606#M56062</link>
      <description>&lt;P&gt;I have to ask, why? &amp;nbsp;The reason is that macro language has its purposes but trying to force simple code through it will create unreadable, unmaintable code. &amp;nbsp;Its quite a simple concept, macro is to generate code which is repeated - to avoid unessecary repeating, it is not there as a replacement for Base SAS which is the programming language. &amp;nbsp;Your example code basically comes down to this:&lt;/P&gt;
&lt;PRE&gt;data hem;
  set chicken;
  importance2=ifn("&amp;amp;TEM.",importance+100,importance+30);
run;
&lt;/PRE&gt;
&lt;P&gt;So if you really need that in a macro (and if I saw that in a macro I would be hitting delete straight away):&lt;/P&gt;
&lt;PRE&gt;%macro Tmp (tem=);
  data hem;
    set chicken;
    importance2=ifn("&amp;amp;TEM.",importance+100,importance+30);
  run;
%mend Tmp;&lt;/PRE&gt;
&lt;P&gt;You will note some simple things to make the code more readable - indentation for instance, simplfying the code to its necessary parts, finishing macro variables with ".".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2016 08:43:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278606#M56062</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-06-20T08:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: sas macro %IF-%THEN/%ELSE Statement, why cannot I generate a second variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278712#M56083</link>
      <description>Thank you very much!!!</description>
      <pubDate>Mon, 20 Jun 2016 15:25:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macro-IF-THEN-ELSE-Statement-why-cannot-I-generate-a-second/m-p/278712#M56083</guid>
      <dc:creator>Bal23</dc:creator>
      <dc:date>2016-06-20T15:25:59Z</dc:date>
    </item>
  </channel>
</rss>

