<?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: &amp;quot;ERROR: Required operator not found in expression&amp;quot; when testing for null in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/quot-ERROR-Required-operator-not-found-in-expression-quot-when/m-p/73059#M15729</link>
    <description>Hi:&lt;BR /&gt;
  Generally, folks don't pass whole IF statements in a %LET. Although it is possible to do,  usually, you want to -do- something if a macro variable exists. Well, what is the thing you want to do?? Usually, it is some kind of conditional process, procedure or data step (or piece of data step program.) &lt;BR /&gt;
&lt;BR /&gt;
I see that as one issue. Then there's the fact that you're passing an IF statement to a macro program and the IF statement will be hanging out in open code, unless you haven't shown the whole program. You can only use an IF statement inside a DATA step program. Don't confuse a data step IF with a macro logic %IF.&lt;BR /&gt;
&lt;BR /&gt;
But, assuming that you haven't shown us all the code, and you are hiding a data step program someplace, I would expect to see a quoting function like %STR or %NRSTR being used to protect the IF statement snippet.&lt;BR /&gt;
 &lt;BR /&gt;
  Even if you DO have a data step program, however, your PUT statement is incorrect. The FORMAT is missing a '.' -- it should be $INTFMT. (your syntax is missing the period. Also, the rest of your code will need to have the rest of the IF statement -- including the action to take on the TRUE and the closing semi-colon.&lt;BR /&gt;
&lt;BR /&gt;
One rule of thumb for macro processing is to start with a working SAS program and then macro-ize the working program. I don't see that you have a working SAS program that can be macro-ized -- where is the rest of your IF statement going to be??  It seems to me that you want to do some kind of error checking -- which is a good thing, but I'd expect to see something like what's shown at the bottom of this posting -- I made up a program to show the difference between a macro %IF and a data step IF.&lt;BR /&gt;
&lt;BR /&gt;
In my program, I show the %IF controllling whether an entire data step program would be run. Alternately, I could have coded the %IF -inside- the DATA step program, but generally error checking and issuing messages in the log is something that's done before a major process starts because if you don't have all of your macro variables with values, you might not want to go forward with the data step program.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
%macro test(exlimitint);&lt;BR /&gt;
                                    &lt;BR /&gt;
%if &amp;amp;exlimitint= %then %do;&lt;BR /&gt;
   %put -------***** EXLIMITINT macro variable is null;&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %if %upcase(&amp;amp;exlimitint) ne SEX %then %do;&lt;BR /&gt;
   %put -------***** You can only ask for the SEX variable;&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %if %upcase(&amp;amp;exlimitint) eq SEX %then %do;&lt;BR /&gt;
proc format;&lt;BR /&gt;
  value $intfmt 'M' = 'FMT VALUE'&lt;BR /&gt;
                'F' = 'XXXXXXXXX';&lt;BR /&gt;
run;&lt;BR /&gt;
                                       &lt;BR /&gt;
data new;&lt;BR /&gt;
  set sashelp.class;&lt;BR /&gt;
  newvar = put(&amp;amp;exlimitint,$intfmt.);&lt;BR /&gt;
  if put(&amp;amp;exlimitint,$intfmt.)='FMT VALUE'&lt;BR /&gt;
     then output;&lt;BR /&gt;
run;&lt;BR /&gt;
                                &lt;BR /&gt;
ods listing;&lt;BR /&gt;
proc print data=new noobs;&lt;BR /&gt;
 title 'Correct macro var and condition';&lt;BR /&gt;
 title2 "Value of EXLIMITINT macro var is: &amp;amp;EXLIMITINT";&lt;BR /&gt;
run;&lt;BR /&gt;
              &lt;BR /&gt;
%end;&lt;BR /&gt;
                       &lt;BR /&gt;
%mend test;&lt;BR /&gt;
              &lt;BR /&gt;
options nodate nonumber center;&lt;BR /&gt;
** invoke with null;&lt;BR /&gt;
%test()&lt;BR /&gt;
             &lt;BR /&gt;
** invoke with SEX (since program uses SASHELP.CLASS);&lt;BR /&gt;
%test(sex)&lt;BR /&gt;
            &lt;BR /&gt;
** invoke with NAME -- not what program is coded for;&lt;BR /&gt;
%test(name)&lt;BR /&gt;
[/pre]</description>
    <pubDate>Wed, 23 Sep 2009 22:33:13 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2009-09-23T22:33:13Z</dc:date>
    <item>
      <title>"ERROR: Required operator not found in expression" when testing for null</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-ERROR-Required-operator-not-found-in-expression-quot-when/m-p/73058#M15728</link>
      <description>Hello!&lt;BR /&gt;
&lt;BR /&gt;
I suspect this problem has something to do with when the variable is being resolved, but I'm not sure how to solve it...&lt;BR /&gt;
&lt;BR /&gt;
Here's a sample of the code I'm using:&lt;BR /&gt;
&lt;BR /&gt;
********&lt;BR /&gt;
%macro test(exlimitint);&lt;BR /&gt;
&lt;BR /&gt;
	%if &amp;amp;exlimitint= %then&lt;BR /&gt;
		%do;&lt;BR /&gt;
			%put variable is null;&lt;BR /&gt;
		%end;&lt;BR /&gt;
&lt;BR /&gt;
	%else&lt;BR /&gt;
		%do;&lt;BR /&gt;
			%put &amp;amp;exlimitint.;&lt;BR /&gt;
		%end;&lt;BR /&gt;
&lt;BR /&gt;
%mend test;&lt;BR /&gt;
***********&lt;BR /&gt;
&lt;BR /&gt;
If I run this with a null value, it works fine.  For example:&lt;BR /&gt;
&lt;BR /&gt;
*********&lt;BR /&gt;
%let exlimitint=;&lt;BR /&gt;
&lt;BR /&gt;
%test(&amp;amp;exlimitint);&lt;BR /&gt;
***********&lt;BR /&gt;
&lt;BR /&gt;
...produces the following log&lt;BR /&gt;
&lt;BR /&gt;
MLOGIC(TEST):  Beginning execution.&lt;BR /&gt;
SYMBOLGEN:  Macro variable EXLIMITINT resolves to&lt;BR /&gt;
MLOGIC(TEST):  Parameter EXLIMITINT has value&lt;BR /&gt;
SYMBOLGEN:  Macro variable EXLIMITINT resolves to&lt;BR /&gt;
MLOGIC(TEST):  %IF condition &amp;amp;exlimitint= is TRUE&lt;BR /&gt;
MLOGIC(TEST):  %PUT variable is null&lt;BR /&gt;
variable is null&lt;BR /&gt;
MLOGIC(TEST):  Ending execution.&lt;BR /&gt;
&lt;BR /&gt;
If I run it with a the variable set to a simple value, it works fine.  Like so...&lt;BR /&gt;
&lt;BR /&gt;
***********&lt;BR /&gt;
%let exlimitint=x;&lt;BR /&gt;
&lt;BR /&gt;
%test(&amp;amp;exlimitint);&lt;BR /&gt;
***********&lt;BR /&gt;
&lt;BR /&gt;
...results in:&lt;BR /&gt;
&lt;BR /&gt;
MLOGIC(TEST):  Beginning execution.&lt;BR /&gt;
SYMBOLGEN:  Macro variable EXLIMITINT resolves to x&lt;BR /&gt;
MLOGIC(TEST):  Parameter EXLIMITINT has value x&lt;BR /&gt;
SYMBOLGEN:  Macro variable EXLIMITINT resolves to x&lt;BR /&gt;
MLOGIC(TEST):  %IF condition &amp;amp;exlimitint= is FALSE&lt;BR /&gt;
MLOGIC(TEST):  %PUT &amp;amp;exlimitint.&lt;BR /&gt;
SYMBOLGEN:  Macro variable EXLIMITINT resolves to x&lt;BR /&gt;
x&lt;BR /&gt;
MLOGIC(TEST):  Ending execution.&lt;BR /&gt;
&lt;BR /&gt;
However, if I try to set the variable to a value that contains a put statement (which is what I actually need), it bombs.&lt;BR /&gt;
&lt;BR /&gt;
*********&lt;BR /&gt;
%let exlimitint=if put(x,$intfmt)='FMT VALUE';&lt;BR /&gt;
&lt;BR /&gt;
%test(&amp;amp;exlimitint);&lt;BR /&gt;
*********&lt;BR /&gt;
&lt;BR /&gt;
MLOGIC(TEST):  Beginning execution.&lt;BR /&gt;
SYMBOLGEN:  Macro variable EXLIMITINT resolves to if put(x,$intfmt)='FMT VALUE'&lt;BR /&gt;
MLOGIC(TEST):  Parameter EXLIMITINT has value if put(x,$intfmt)='FMT VALUE'&lt;BR /&gt;
SYMBOLGEN:  Macro variable EXLIMITINT resolves to if put(x,$intfmt)='FMT VALUE'&lt;BR /&gt;
ERROR: Required operator not found in expression: &amp;amp;exlimitint=&lt;BR /&gt;
ERROR: The macro TEST will stop executing.&lt;BR /&gt;
MLOGIC(TEST):  Ending execution.&lt;BR /&gt;
&lt;BR /&gt;
Thoughts, anyone?  &lt;BR /&gt;
&lt;BR /&gt;
Thanks!!!&lt;BR /&gt;
Emily</description>
      <pubDate>Wed, 23 Sep 2009 20:59:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-ERROR-Required-operator-not-found-in-expression-quot-when/m-p/73058#M15728</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-09-23T20:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: "ERROR: Required operator not found in expression" when testing for null</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-ERROR-Required-operator-not-found-in-expression-quot-when/m-p/73059#M15729</link>
      <description>Hi:&lt;BR /&gt;
  Generally, folks don't pass whole IF statements in a %LET. Although it is possible to do,  usually, you want to -do- something if a macro variable exists. Well, what is the thing you want to do?? Usually, it is some kind of conditional process, procedure or data step (or piece of data step program.) &lt;BR /&gt;
&lt;BR /&gt;
I see that as one issue. Then there's the fact that you're passing an IF statement to a macro program and the IF statement will be hanging out in open code, unless you haven't shown the whole program. You can only use an IF statement inside a DATA step program. Don't confuse a data step IF with a macro logic %IF.&lt;BR /&gt;
&lt;BR /&gt;
But, assuming that you haven't shown us all the code, and you are hiding a data step program someplace, I would expect to see a quoting function like %STR or %NRSTR being used to protect the IF statement snippet.&lt;BR /&gt;
 &lt;BR /&gt;
  Even if you DO have a data step program, however, your PUT statement is incorrect. The FORMAT is missing a '.' -- it should be $INTFMT. (your syntax is missing the period. Also, the rest of your code will need to have the rest of the IF statement -- including the action to take on the TRUE and the closing semi-colon.&lt;BR /&gt;
&lt;BR /&gt;
One rule of thumb for macro processing is to start with a working SAS program and then macro-ize the working program. I don't see that you have a working SAS program that can be macro-ized -- where is the rest of your IF statement going to be??  It seems to me that you want to do some kind of error checking -- which is a good thing, but I'd expect to see something like what's shown at the bottom of this posting -- I made up a program to show the difference between a macro %IF and a data step IF.&lt;BR /&gt;
&lt;BR /&gt;
In my program, I show the %IF controllling whether an entire data step program would be run. Alternately, I could have coded the %IF -inside- the DATA step program, but generally error checking and issuing messages in the log is something that's done before a major process starts because if you don't have all of your macro variables with values, you might not want to go forward with the data step program.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
%macro test(exlimitint);&lt;BR /&gt;
                                    &lt;BR /&gt;
%if &amp;amp;exlimitint= %then %do;&lt;BR /&gt;
   %put -------***** EXLIMITINT macro variable is null;&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %if %upcase(&amp;amp;exlimitint) ne SEX %then %do;&lt;BR /&gt;
   %put -------***** You can only ask for the SEX variable;&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %if %upcase(&amp;amp;exlimitint) eq SEX %then %do;&lt;BR /&gt;
proc format;&lt;BR /&gt;
  value $intfmt 'M' = 'FMT VALUE'&lt;BR /&gt;
                'F' = 'XXXXXXXXX';&lt;BR /&gt;
run;&lt;BR /&gt;
                                       &lt;BR /&gt;
data new;&lt;BR /&gt;
  set sashelp.class;&lt;BR /&gt;
  newvar = put(&amp;amp;exlimitint,$intfmt.);&lt;BR /&gt;
  if put(&amp;amp;exlimitint,$intfmt.)='FMT VALUE'&lt;BR /&gt;
     then output;&lt;BR /&gt;
run;&lt;BR /&gt;
                                &lt;BR /&gt;
ods listing;&lt;BR /&gt;
proc print data=new noobs;&lt;BR /&gt;
 title 'Correct macro var and condition';&lt;BR /&gt;
 title2 "Value of EXLIMITINT macro var is: &amp;amp;EXLIMITINT";&lt;BR /&gt;
run;&lt;BR /&gt;
              &lt;BR /&gt;
%end;&lt;BR /&gt;
                       &lt;BR /&gt;
%mend test;&lt;BR /&gt;
              &lt;BR /&gt;
options nodate nonumber center;&lt;BR /&gt;
** invoke with null;&lt;BR /&gt;
%test()&lt;BR /&gt;
             &lt;BR /&gt;
** invoke with SEX (since program uses SASHELP.CLASS);&lt;BR /&gt;
%test(sex)&lt;BR /&gt;
            &lt;BR /&gt;
** invoke with NAME -- not what program is coded for;&lt;BR /&gt;
%test(name)&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 23 Sep 2009 22:33:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-ERROR-Required-operator-not-found-in-expression-quot-when/m-p/73059#M15729</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-09-23T22:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: "ERROR: Required operator not found in expression" when testing for null</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-ERROR-Required-operator-not-found-in-expression-quot-when/m-p/73060#M15730</link>
      <description>I do this all the time with SAS - using SAS macro variables as code exit-points but you need to surround your macro variable using %QUOTE (* your code goes here;);&lt;BR /&gt;
&lt;BR /&gt;
Also, I encourage you to code your macro language %IF &lt;EXPRESSION&gt; %THEN  %-whatever-;   statements so that there is never an unbalanced condition with the operator -- for readability I choose to use the . (period) character.  Another technique if you are checking for a zero-length is to use the %LENGTH(&amp;amp;macrovar) and then do some logic accordingly.&lt;BR /&gt;
&lt;BR /&gt;
And in some unique cases, you will need to call upon some of the more complex macro language functions for resolution.  So I suggest you get familiar with the ins/outs of macro function and make extensive use of the most-valuable forum resources like Cynthia but more importantly get used to checking the SAS Support &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;  website for SAS-hosted DOC and supplemental technical and conference topic-related reference material.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/EXPRESSION&gt;</description>
      <pubDate>Wed, 23 Sep 2009 23:41:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-ERROR-Required-operator-not-found-in-expression-quot-when/m-p/73060#M15730</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-09-23T23:41:26Z</dc:date>
    </item>
  </channel>
</rss>

