<?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: Macro variable to call a code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-to-call-a-code/m-p/270255#M53668</link>
    <description>&lt;P&gt;The code you have written is valid.&amp;nbsp; What is the problem you are having?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note you may have a typo, currently IF condition and the ELSE IF condition are the same.&amp;nbsp; So the else if would never execute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As written your code will resolve to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data a; set intermediate_file;
if 1=2 then do;
  number=1;end;
else
if 1=2 then do
 number=0;end;
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is unusual to have an IF statement that evaulates an expresssion with no variables, but it's valid code.&amp;nbsp; Since both the IF expression and the ELSE IF expression are false, the assignment statement will never be executed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: noticed you are missing a semicolon after the second DO.&lt;/P&gt;</description>
    <pubDate>Fri, 13 May 2016 03:24:08 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2016-05-13T03:24:08Z</dc:date>
    <item>
      <title>Macro variable to call a code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-to-call-a-code/m-p/270253#M53666</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I have a macro variable which is used to dictate what operation to be conducted.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%let CODE=1;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;and I want to get something like the below. There is no variable in the dataset has the name code.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;data a; set intermediate_file;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if &amp;amp;code=2 then do;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; number=1;end;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if &amp;amp;code=2 then do&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;number=0;end;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Could you please help me with that?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;HHC&lt;/SPAN&gt;&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>Fri, 13 May 2016 02:51:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-to-call-a-code/m-p/270253#M53666</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2016-05-13T02:51:22Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable to call a code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-to-call-a-code/m-p/270254#M53667</link>
      <description>&lt;P&gt;Other than your IF condition being the same and not quite making sense your code should work as presented.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Both your conditions compare to the #2, which isn't what you intended.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can compare strings to strings and numbers to numbers so your macro variables don't have to resolve to a variable.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2016 03:18:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-to-call-a-code/m-p/270254#M53667</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-13T03:18:17Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable to call a code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-to-call-a-code/m-p/270255#M53668</link>
      <description>&lt;P&gt;The code you have written is valid.&amp;nbsp; What is the problem you are having?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note you may have a typo, currently IF condition and the ELSE IF condition are the same.&amp;nbsp; So the else if would never execute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As written your code will resolve to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data a; set intermediate_file;
if 1=2 then do;
  number=1;end;
else
if 1=2 then do
 number=0;end;
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is unusual to have an IF statement that evaulates an expresssion with no variables, but it's valid code.&amp;nbsp; Since both the IF expression and the ELSE IF expression are false, the assignment statement will never be executed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: noticed you are missing a semicolon after the second DO.&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2016 03:24:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-to-call-a-code/m-p/270255#M53668</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2016-05-13T03:24:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable to call a code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-to-call-a-code/m-p/270318#M53691</link>
      <description>&lt;P&gt;While unusual, your approach is fine. &amp;nbsp;The strange part is making the same comparison both times:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if &amp;amp;code=2 then do ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Shouldn't one of those be changed to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if &amp;amp;code=1 then do ....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fixing the missing semicolon can't hurt, but it's a lucky accident that the code will work anyway.&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2016 11:20:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-to-call-a-code/m-p/270318#M53691</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-05-13T11:20:34Z</dc:date>
    </item>
  </channel>
</rss>

