<?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 Macro Validation - &amp;quot;NOT in (0 1)&amp;quot; not working in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Validation-quot-NOT-in-0-1-quot-not-working/m-p/763790#M241892</link>
    <description>&lt;P&gt;I have written a macro function, and the following toy example shows my problem. So my problem is that my validation of arguments does not work. For example, I would like to check that:&amp;nbsp;&lt;BR /&gt;-&amp;nbsp;&lt;CODE class=" language-sas"&gt;SomeMacroVariableArgument is&amp;nbsp;1 (My original function will take a macro variable argument and that's why I added it here to replicate my original example as much as possible).&lt;/CODE&gt;&lt;BR /&gt;- Boolean1 and Boolean2 are either 0 or 1. &lt;BR /&gt;&lt;BR /&gt;Running this code:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let TestVar = 1; 

%macro MyFun(Argument1, SomeMacroVariableArgument, Boolean1, Boolean2); /minoperator mindelimiter=' ';

/*--------------------------------------------------------------*/
/* Some Validation*/
/*--------------------------------------------------------------*/

	%if &amp;amp;TestVar. NE 1 or &amp;amp;Boolean1. not in (0 1) or &amp;amp;Boolean2. not in (0 1) %then %do; 
		%if &amp;amp;SomeMacroVariableArgument. NE 1 %then %do; 
			%put ERROR: This variable should be 1 ;
		%end; 

		%if &amp;amp;Boolean1. not in (0 1) %then %do; 
			%put ERROR: Boolean1 should be 0 or 1 ;
		%end; 

		%if &amp;amp;Boolean2. not in (0 1) %then %do; 
			%put ERROR: Boolean2 should be 0 or 1 ;
		%end; 

	%put ERROR: Macro not executed due to invalid parameters ;
	%end; 
/*--------------------------------------------------------------*/
/* The main functionality of the Macro given that the validation showed no error.*/
/*--------------------------------------------------------------*/
	%else %do; 
		data MyData; 
			Argument1 = &amp;amp;Argument1.; 
		run; 
	%end;
 
%mend MyFun; 

%put test = %MyFun(1,&amp;amp;Testvar. ,0,0); &amp;nbsp;/* This&amp;nbsp;yields&amp;nbsp;an&amp;nbsp;error&amp;nbsp;message&amp;nbsp;/*&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;The error message I got is:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &lt;BR /&gt;&amp;amp;TestVar. NE 1 or &amp;amp;Boolean1. not in (0 1) or &amp;amp;Boolean2. not in (0 1) &lt;BR /&gt;ERROR: The macro MYFUN will stop executing.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the problem and how can I fix it? I believe it is clear that the purpose with the validation is to check that &lt;CODE class=" language-sas"&gt;SomeMacroVariableArgument is&amp;nbsp;1&amp;nbsp;and&amp;nbsp;&lt;/CODE&gt;the Boolean1 and Boolean2 arguments are either 0 or 1.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Extra question 1:&amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;When using the logical or, I assume it means that atleast one of the conditions is forfilled, not that just one of them is?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Extra question 2:&amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;According to&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lrcon/p00iah2thp63bmn1lt20esag14lh.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lrcon/p00iah2thp63bmn1lt20esag14lh.htm&lt;/A&gt;&amp;nbsp;, the symbol for the logical NE depends on your computer. I could for instance use ^= or ~= instead of NE; how do I know which "my computer" uses?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;All advice appreciated.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Aug 2021 07:23:52 GMT</pubDate>
    <dc:creator>SasStatistics</dc:creator>
    <dc:date>2021-08-25T07:23:52Z</dc:date>
    <item>
      <title>Macro Validation - "NOT in (0 1)" not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Validation-quot-NOT-in-0-1-quot-not-working/m-p/763790#M241892</link>
      <description>&lt;P&gt;I have written a macro function, and the following toy example shows my problem. So my problem is that my validation of arguments does not work. For example, I would like to check that:&amp;nbsp;&lt;BR /&gt;-&amp;nbsp;&lt;CODE class=" language-sas"&gt;SomeMacroVariableArgument is&amp;nbsp;1 (My original function will take a macro variable argument and that's why I added it here to replicate my original example as much as possible).&lt;/CODE&gt;&lt;BR /&gt;- Boolean1 and Boolean2 are either 0 or 1. &lt;BR /&gt;&lt;BR /&gt;Running this code:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let TestVar = 1; 

%macro MyFun(Argument1, SomeMacroVariableArgument, Boolean1, Boolean2); /minoperator mindelimiter=' ';

/*--------------------------------------------------------------*/
/* Some Validation*/
/*--------------------------------------------------------------*/

	%if &amp;amp;TestVar. NE 1 or &amp;amp;Boolean1. not in (0 1) or &amp;amp;Boolean2. not in (0 1) %then %do; 
		%if &amp;amp;SomeMacroVariableArgument. NE 1 %then %do; 
			%put ERROR: This variable should be 1 ;
		%end; 

		%if &amp;amp;Boolean1. not in (0 1) %then %do; 
			%put ERROR: Boolean1 should be 0 or 1 ;
		%end; 

		%if &amp;amp;Boolean2. not in (0 1) %then %do; 
			%put ERROR: Boolean2 should be 0 or 1 ;
		%end; 

	%put ERROR: Macro not executed due to invalid parameters ;
	%end; 
/*--------------------------------------------------------------*/
/* The main functionality of the Macro given that the validation showed no error.*/
/*--------------------------------------------------------------*/
	%else %do; 
		data MyData; 
			Argument1 = &amp;amp;Argument1.; 
		run; 
	%end;
 
%mend MyFun; 

%put test = %MyFun(1,&amp;amp;Testvar. ,0,0); &amp;nbsp;/* This&amp;nbsp;yields&amp;nbsp;an&amp;nbsp;error&amp;nbsp;message&amp;nbsp;/*&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;The error message I got is:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &lt;BR /&gt;&amp;amp;TestVar. NE 1 or &amp;amp;Boolean1. not in (0 1) or &amp;amp;Boolean2. not in (0 1) &lt;BR /&gt;ERROR: The macro MYFUN will stop executing.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the problem and how can I fix it? I believe it is clear that the purpose with the validation is to check that &lt;CODE class=" language-sas"&gt;SomeMacroVariableArgument is&amp;nbsp;1&amp;nbsp;and&amp;nbsp;&lt;/CODE&gt;the Boolean1 and Boolean2 arguments are either 0 or 1.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Extra question 1:&amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;When using the logical or, I assume it means that atleast one of the conditions is forfilled, not that just one of them is?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Extra question 2:&amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;According to&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lrcon/p00iah2thp63bmn1lt20esag14lh.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lrcon/p00iah2thp63bmn1lt20esag14lh.htm&lt;/A&gt;&amp;nbsp;, the symbol for the logical NE depends on your computer. I could for instance use ^= or ~= instead of NE; how do I know which "my computer" uses?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;All advice appreciated.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Aug 2021 07:23:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Validation-quot-NOT-in-0-1-quot-not-working/m-p/763790#M241892</guid>
      <dc:creator>SasStatistics</dc:creator>
      <dc:date>2021-08-25T07:23:52Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Validation - "NOT in (0 1)" not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Validation-quot-NOT-in-0-1-quot-not-working/m-p/763792#M241894</link>
      <description>&lt;P&gt;The macro processor does understand the IN operator, but not the NOT IN operator combination. You need to negate your conditions differently:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let TestVar = 1; 

%macro MyFun(Argument1, SomeMacroVariableArgument, Boolean1, Boolean2) /minoperator mindelimiter=' ';

/*--------------------------------------------------------------*/
/* Some Validation*/
/*--------------------------------------------------------------*/

	%if &amp;amp;TestVar. NE 1 or not (&amp;amp;Boolean1. in (0 1)) or not (&amp;amp;Boolean2. in (0 1)) %then %do; 
		%if &amp;amp;SomeMacroVariableArgument. NE 1 %then %do; 
			%put ERROR: This variable should be 1 ;
		%end; 

		%if not (&amp;amp;Boolean1. in (0 1)) %then %do; 
			%put ERROR: Boolean1 should be 0 or 1 ;
		%end; 

		%if not (&amp;amp;Boolean2. in (0 1)) %then %do; 
			%put ERROR: Boolean2 should be 0 or 1 ;
		%end; 

	%put ERROR: Macro not executed due to invalid parameters ;
	%end; 
/*--------------------------------------------------------------*/
/* The main functionality of the Macro given that the validation showed no error.*/
/*--------------------------------------------------------------*/
	%else %do; 
		data MyData; 
			Argument1 = &amp;amp;Argument1.; 
		run; 
	%end;
 
%mend MyFun; 

%MyFun(1,&amp;amp;Testvar. ,0,0);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since the macro generates data step code, do not use it in a %PUT statement, as the first semicolon created will terminate that %PUT, but the adjacent statement will not be recognized, as it becomes part of the %PUT.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Aug 2021 07:33:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Validation-quot-NOT-in-0-1-quot-not-working/m-p/763792#M241894</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-08-25T07:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Validation - "NOT in (0 1)" not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Validation-quot-NOT-in-0-1-quot-not-working/m-p/763794#M241896</link>
      <description>&lt;P&gt;And the MINDELIMITER and MINOPERATOR options have to be part of the %MACRO statement, so there must not be a semicolon after the closing bracket of the macro parameters.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Aug 2021 07:38:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Validation-quot-NOT-in-0-1-quot-not-working/m-p/763794#M241896</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-08-25T07:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Validation - "NOT in (0 1)" not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Validation-quot-NOT-in-0-1-quot-not-working/m-p/763832#M241914</link>
      <description>Is this not the case in the example code?</description>
      <pubDate>Wed, 25 Aug 2021 13:08:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Validation-quot-NOT-in-0-1-quot-not-working/m-p/763832#M241914</guid>
      <dc:creator>SasStatistics</dc:creator>
      <dc:date>2021-08-25T13:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Validation - "NOT in (0 1)" not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Validation-quot-NOT-in-0-1-quot-not-working/m-p/763840#M241917</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381436"&gt;@SasStatistics&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Extra question 2:&amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;According to&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lrcon/p00iah2thp63bmn1lt20esag14lh.htm" target="_blank" rel="noopener"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lrcon/p00iah2thp63bmn1lt20esag14lh.htm&lt;/A&gt;&amp;nbsp;, the symbol for the logical NE depends on your computer. I could for instance use ^= or ~= instead of NE; how do I know which "my computer" uses?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why not just use NE then you don't need to know.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that on a EBCDIC computer (IBM mainframe) t&lt;SPAN&gt;he standard logical NOT symbol is&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;¬&lt;/STRONG&gt;&lt;SPAN&gt;, which corresponds to EBCDIC code point X'5F'.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Just don't try to use &amp;lt;&amp;gt; as meaning NE because you will very surprised by the results.&amp;nbsp; You can get away with it in SQL code (but why confuse yourself?).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You can always try it to see:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;434   data test;
435     x1= 3 ne 2;
436     x2= 3 ^= 2;
437     x3= 3 ~= 2;
438   /* for ebcidic computers use the actual not symbol instead of ascii characters ~ or ^ */
439   * But never do this ! ;
440     x4= 3 &amp;lt;&amp;gt; 2;
NOTE: The "&amp;lt;&amp;gt;" operator is interpreted as "MAX".
441     x5= 3 &amp;gt;&amp;lt; 2;
442     put (x1-x5) (=);
443   run;

x1=1 x2=1 x3=1 x4=3 x5=2
NOTE: The data set WORK.TEST has 1 observations and 5 variables.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Aug 2021 14:00:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Validation-quot-NOT-in-0-1-quot-not-working/m-p/763840#M241917</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-25T14:00:59Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Validation - "NOT in (0 1)" not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Validation-quot-NOT-in-0-1-quot-not-working/m-p/763944#M241949</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381436"&gt;@SasStatistics&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Is this not the case in the example code?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Quote from your post:&lt;/P&gt;
&lt;PRE&gt;%macro MyFun(Argument1, SomeMacroVariableArgument, Boolean1, Boolean2)&lt;FONT color="#FF0000"&gt;;&lt;/FONT&gt; /minoperator mindelimiter=' ';&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Aug 2021 18:20:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Validation-quot-NOT-in-0-1-quot-not-working/m-p/763944#M241949</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-08-25T18:20:14Z</dc:date>
    </item>
  </channel>
</rss>

