<?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: Two simple Macro examples - conditional logic in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/748982#M235294</link>
    <description>&lt;P&gt;Thank you, it clarified things very much.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Now this is really weird to me:&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;In the code below, I use for instance %IF since I am testing a macro variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro MyFun3(random); 
	data MyData; 
		set sashelp.cars(obs=2);
      	length NewCol $ 30;

			%if &amp;amp;random. = "AA" %then NewCol = 'AA'; 
			%else %if &amp;amp;random. = "BB" %then NewCol = 'BB';
			%else %do;
       			 *if _N_ = 1 then put "WARNING: Write something valid"; * Removed this from an solution suggestion since I don't fully understand it yet. ; 
        		NewCol = "Write something valid"; 
        	%end;
	run;  
%mend MyFun3;

%MyFun3(AA);  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This code yields the result:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SasStatistics_0-1624044584869.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60507iE48D2B58DC9E2B70/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SasStatistics_0-1624044584869.png" alt="SasStatistics_0-1624044584869.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;As seen from the red box, it does not accept AA as the argument I was thinking of it to be.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;The right thing to do (As indicated in the answers above) would be to write the code:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro MyFun3(random); 
	data MyData; 
		set sashelp.cars(obs=2);
      	length NewCol $ 30;

			if "&amp;amp;random." = "AA" then NewCol = 'AA'; 
			else if "&amp;amp;random." = "BB" then NewCol = 'BB';
			else do;
       			 *if _N_ = 1 then put "WARNING: Write something valid";
        		NewCol = "Write something valid"; 
        	end;
	run;  
%mend MyFun3;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So now we for instance have&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;"&amp;amp;random."&lt;/PRE&gt;
&lt;P&gt;which is seen as a string rather than a macro? I could understand this with "Back-engineering" (understanding it given the solution) but would have big trouble coming up with it myself?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Why is the first code wrong?&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thanks.&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>Fri, 18 Jun 2021 19:36:35 GMT</pubDate>
    <dc:creator>SasStatistics</dc:creator>
    <dc:date>2021-06-18T19:36:35Z</dc:date>
    <item>
      <title>Two simple Macro examples - conditional logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/748840#M235237</link>
      <description>&lt;P&gt;I am writing a bigger script and basically need the following principles to work which I demonstrate by two examples (demonstrating different concepts):&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Example 1. Depending on the positional argument, I want to set different data sets:&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro MyFun2(random); 
	data MyData; 
		if &amp;amp;random. = AA then do; 
			set sashelp.cars(obs=2);
		end; 
		else if &amp;amp;random. = BB then do; 
			set sashelp.cars(obs=3);
		end; 
	run; 
%mend MyFun2;

%MyFun2(AA);  
%MyFun2(BB);  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Result is:&amp;nbsp;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SasStatistics_0-1624001780542.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60465i241E3E01BB62A900/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SasStatistics_0-1624001780542.png" alt="SasStatistics_0-1624001780542.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Notice how the two first columns are created.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;One message in the log is related to "Uninitialized variable" which I read about here&amp;nbsp;&lt;A href="http://statskom.com/sas-tips-tricks-9-note-variable-x-is-uninitialized/" target="_blank" rel="noopener"&gt;http://statskom.com/sas-tips-tricks-9-note-variable-x-is-uninitialized/&lt;/A&gt;&amp;nbsp;. Nevertheless, I am not fully sure of how to handle it properly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example 2. Depending on the positional argument, I want to create a new column taking different values:&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Notice the comment in the code below, it is obivously wrong but I don't know how to handle it properly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro MyFun3(random); 
	data MyData; 
		set sashelp.cars(obs=2);
			if &amp;amp;random. = AA then NewCol = 'AA'; 

			else if &amp;amp;random. = BB then NewCol = 'BB';

			else NewCol = "Write something valid";&lt;STRONG&gt; *This is obiviously wrong, but I would somehow like to do: if &amp;amp;random. is not equal to AA or BB, then assign the value "Write something valid" to NewColumn.;&lt;/STRONG&gt;
	run;  
%mend MyFun3;

%MyFun3(AA);  
%MyFun3(BB);  
%MyFun3(Test);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code does not run, I don't write the log since the code can be easily reproduced.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope it is clear of what I want to achieve. All advice of how to properly do what I want is appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jun 2021 07:44:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/748840#M235237</guid>
      <dc:creator>SasStatistics</dc:creator>
      <dc:date>2021-06-18T07:44:57Z</dc:date>
    </item>
    <item>
      <title>Re: Two simple Macro examples - conditional logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/748843#M235238</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;@1) Maxim No. 1 says: "Read the log".&amp;nbsp; Log says:&lt;/P&gt;
&lt;PRE&gt;1    %macro MyFun2(random);
2      data MyData;
3        if &amp;amp;random. = AA then do;
4          set sashelp.cars(obs=2);
5        end;
6        else if &amp;amp;random. = BB then do;
7          set sashelp.cars(obs=3);
8        end;
9      run;
10   %mend MyFun2;
11
12   %MyFun2(AA);

NOTE: Variable AA is uninitialized.
NOTE: Variable BB is uninitialized.
NOTE: There were 2 observations read from the data set SASHELP.CARS.
NOTE: The data set WORK.MYDATA has 2 observations and 17 variables.
NOTE: DATA statement used (Total process time):
      real time           0.09 seconds
      cpu time            0.03 seconds


13   %MyFun2(BB);

NOTE: Variable BB is uninitialized.
NOTE: Variable AA is uninitialized.
NOTE: There were 2 observations read from the data set SASHELP.CARS.
NOTE: The data set WORK.MYDATA has 2 observations and 17 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
&lt;/PRE&gt;
&lt;P&gt;Modify your code the following way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro MyFun2(random); 
	data MyData; 
		%if &amp;amp;random. = AA %then %do; 
			set sashelp.cars(obs=2);
		%end; 
		%else %if &amp;amp;random. = BB %then %do; 
			set sashelp.cars(obs=3);
		%end; 
	run; 
%mend MyFun2;

%MyFun2(AA);  
%MyFun2(BB);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log will be clean and if you add `mprint` option you will see the code of data step that was executed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;@2)&amp;nbsp; The same, read the log.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Modify your code for example like that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro MyFun3(random); 
	data MyData; 
		set sashelp.cars(obs=2);

      length NewCol $ 30;

			if "&amp;amp;random." = "AA" then NewCol = 'AA'; 

			else if "&amp;amp;random." = "BB" then NewCol = 'BB';

			else 
        do;
        if _N_ = 1 then put "WARNING: Write something valid";
        NewCol = "Write something valid"; /*This is obiviously wrong, but I would somehow like to do: if &amp;amp;random. is not equal to AA or BB, then assign the value "Write something valid" to NewColumn.;*/
        end;
	run;  
%mend MyFun3;

%MyFun3(AA);  
%MyFun3(BB);  
%MyFun3(Test);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jun 2021 08:23:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/748843#M235238</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-06-18T08:23:54Z</dc:date>
    </item>
    <item>
      <title>Re: Two simple Macro examples - conditional logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/748851#M235242</link>
      <description>You have to put % before the if and then and the do. Also try mprint mlogic and symbolgen for debugging.</description>
      <pubDate>Fri, 18 Jun 2021 10:18:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/748851#M235242</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-06-18T10:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: Two simple Macro examples - conditional logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/748852#M235243</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381436"&gt;@SasStatistics&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%IF and IF (without the %) do not do the same thing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%IF tests the value of macro variables.&lt;/P&gt;
&lt;P&gt;IF tests the value of data step variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you write macro code, or code involving macro variables, you need to ask yourself if you are testing the value of a macro variable, or testing the value of a data step variable, to be sure you have the right one (%IF or IF).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's look at your Example 1. Are you trying to test the value of a macro variable, or a data step variable? What is your answer?&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jun 2021 11:02:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/748852#M235243</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-18T11:02:58Z</dc:date>
    </item>
    <item>
      <title>Re: Two simple Macro examples - conditional logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/748878#M235257</link>
      <description>&lt;P&gt;You've received good advice on understanding the difference between &lt;EM&gt;&lt;STRONG&gt;%if&lt;/STRONG&gt;&lt;/EM&gt; and &lt;EM&gt;&lt;STRONG&gt;if&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp; (and &lt;EM&gt;&lt;STRONG&gt;%then&lt;/STRONG&gt;&lt;/EM&gt; vs &lt;EM&gt;&lt;STRONG&gt;then&lt;/STRONG&gt;&lt;/EM&gt;,&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;%do&lt;/STRONG&gt;&lt;/EM&gt; vs &lt;EM&gt;&lt;STRONG&gt;do&lt;/STRONG&gt;&lt;/EM&gt;,&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;%end&lt;/STRONG&gt;&lt;/EM&gt;&lt;EM&gt; vs&amp;nbsp;&lt;STRONG&gt;end&lt;/STRONG&gt;&lt;/EM&gt;) in macro coding.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below, I suggest another consideration in writing and using macros: avoid code duplication - a major benefit of good macro coding.&amp;nbsp; In the case of Example 1, you have two instances of a DATA step, which vary only in the SET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So instead, in your macro code, make a new macro variable DSN, as follows (which also eliminates the need for &lt;EM&gt;&lt;STRONG&gt;%do&lt;/STRONG&gt;&lt;/EM&gt; and &lt;EM&gt;&lt;STRONG&gt;%end&lt;/STRONG&gt;&lt;/EM&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro MyFun(random); 
   %local dsn ;
   %if       &amp;amp;random. = AA %then %let dsn=sashelp.cars(obs=2);
   %else %if &amp;amp;random. = BB %then %let dsn=sashelp.cars(obs=3);
   %else %goto eom ;
  data MyData; 
    set &amp;amp;dsn ;
  run; 
%eom: %mend MyFun2;

options mprint;
%MyFun2(AA);  
%MyFun2(BB);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is especially useful if the embedded DATA step is long - needless duplication creates more chances for error, and makes code maintenance more difficult.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jun 2021 13:19:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/748878#M235257</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-06-18T13:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: Two simple Macro examples - conditional logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/748980#M235293</link>
      <description>Thanks. What is eom in this case doing?</description>
      <pubDate>Fri, 18 Jun 2021 19:19:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/748980#M235293</guid>
      <dc:creator>SasStatistics</dc:creator>
      <dc:date>2021-06-18T19:19:49Z</dc:date>
    </item>
    <item>
      <title>Re: Two simple Macro examples - conditional logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/748982#M235294</link>
      <description>&lt;P&gt;Thank you, it clarified things very much.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Now this is really weird to me:&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;In the code below, I use for instance %IF since I am testing a macro variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro MyFun3(random); 
	data MyData; 
		set sashelp.cars(obs=2);
      	length NewCol $ 30;

			%if &amp;amp;random. = "AA" %then NewCol = 'AA'; 
			%else %if &amp;amp;random. = "BB" %then NewCol = 'BB';
			%else %do;
       			 *if _N_ = 1 then put "WARNING: Write something valid"; * Removed this from an solution suggestion since I don't fully understand it yet. ; 
        		NewCol = "Write something valid"; 
        	%end;
	run;  
%mend MyFun3;

%MyFun3(AA);  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This code yields the result:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SasStatistics_0-1624044584869.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60507iE48D2B58DC9E2B70/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SasStatistics_0-1624044584869.png" alt="SasStatistics_0-1624044584869.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;As seen from the red box, it does not accept AA as the argument I was thinking of it to be.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;The right thing to do (As indicated in the answers above) would be to write the code:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro MyFun3(random); 
	data MyData; 
		set sashelp.cars(obs=2);
      	length NewCol $ 30;

			if "&amp;amp;random." = "AA" then NewCol = 'AA'; 
			else if "&amp;amp;random." = "BB" then NewCol = 'BB';
			else do;
       			 *if _N_ = 1 then put "WARNING: Write something valid";
        		NewCol = "Write something valid"; 
        	end;
	run;  
%mend MyFun3;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So now we for instance have&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;"&amp;amp;random."&lt;/PRE&gt;
&lt;P&gt;which is seen as a string rather than a macro? I could understand this with "Back-engineering" (understanding it given the solution) but would have big trouble coming up with it myself?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Why is the first code wrong?&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thanks.&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>Fri, 18 Jun 2021 19:36:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/748982#M235294</guid>
      <dc:creator>SasStatistics</dc:creator>
      <dc:date>2021-06-18T19:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: Two simple Macro examples - conditional logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/748986#M235295</link>
      <description>&lt;P&gt;Your code should be like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro MyFun3(random); 
	data MyData; 
		set sashelp.cars(obs=2);
      	length NewCol $ 30;

			%if &amp;amp;random. = AA %then 
        %do; 
          NewCol = 'AA'; 
        %end;
			%else %if &amp;amp;random. = BB %then 
        %do;
          NewCol = 'BB';
        %end;
			%else 
        %do;
          /*if _N_ = 1 then put "WARNING: Write something valid"; * Removed this from an solution suggestion since I don't fully understand it yet. ; */
          NewCol = "Write something valid"; 
       	%end;
	run;  
%mend MyFun3;

%MyFun3(AA);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;From macro language perspective _every_ value is a text so quotes are unnecessary.&lt;/P&gt;
&lt;P&gt;To test if value of macro variable X is ABC you just write:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;X. = ABC %then...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Quotes are necessary on the 4GL language level, because you want to inform compilator that value `AB` is in fact a string text ("AB") an not a variable name (AB)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;P.S. Always, always, always use block comments ( /* comment */) in macros.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jun 2021 20:12:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/748986#M235295</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-06-18T20:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: Two simple Macro examples - conditional logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/748988#M235297</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options minoperator mprint mlogic symbolgen;
%macro MyFun3(random) / minoperator; 
	data MyData; 
		set sashelp.cars(obs=2);
			%if &amp;amp;random. in (AA BB) %then %do;
			NewCol ="&amp;amp;random";
			%end;
			%else %do;
			NewCol="Write something valid";
			%end;
	run;  
	
	proc print data=mydata;
	run;
%mend MyFun3;

%MyFun3(AA);  
%MyFun3(BB);  
%MyFun3(Test);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use minoperator. Also, you don't need to hardcode 'AA' and 'BB' if it's the same as the value of &amp;amp;random.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jun 2021 20:41:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/748988#M235297</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-06-18T20:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: Two simple Macro examples - conditional logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/748995#M235302</link>
      <description>&lt;P&gt;Take a step back and internalize these sentences:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;"The macro language is a&amp;nbsp;&lt;EM&gt;code generator&lt;/EM&gt; that does its work&amp;nbsp;&lt;EM&gt;before&lt;/EM&gt; any code is actually executed"&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;"The macro language has one data type only: TEXT"&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;From this, you will get the answers to your questions.&lt;/P&gt;
&lt;P&gt;From the first, you get that you can never access the values of data step/dataset variables in a macro statement.&lt;/P&gt;
&lt;P&gt;From the second sentence, you get that no quotes are needed, they are actually part of the "data" (text).&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jun 2021 21:17:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/748995#M235302</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-18T21:17:54Z</dc:date>
    </item>
    <item>
      <title>Re: Two simple Macro examples - conditional logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/748996#M235303</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;@1) Maxim No. 1 says: "Read the log".&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It's actually Maxim 2 &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jun 2021 21:21:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/748996#M235303</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-18T21:21:18Z</dc:date>
    </item>
    <item>
      <title>Re: Two simple Macro examples - conditional logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/749038#M235323</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;@1) Maxim No. 1 says: "Read the log".&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It's actually Maxim 2 &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":thinking_face:"&gt;🤔&lt;/span&gt; So maybe it's time for&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;Maxim 0:&amp;nbsp; Read the maxim's.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Jun 2021 17:28:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/749038#M235323</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-06-19T17:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: Two simple Macro examples - conditional logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/749044#M235326</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;@1) Maxim No. 1 says: "Read the log".&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It's actually Maxim 2 &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":thinking_face:"&gt;🤔&lt;/span&gt; So maybe it's time for&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;Maxim 0:&amp;nbsp; Read the maxim's.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Good point Mark (&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;)!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Sorry Kurt (&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;) I was quoting off the top of my head.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":nerd_face:"&gt;🤓&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Sat, 19 Jun 2021 19:00:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-simple-Macro-examples-conditional-logic/m-p/749044#M235326</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-06-19T19:00:37Z</dc:date>
    </item>
  </channel>
</rss>

