DATA Step, Macro, Functions and more

Question on %IF not =

Accepted Solution Solved
Reply
Contributor
Posts: 31
Accepted Solution

Question on %IF not =

Hi All,

I am trying to execute the following code.  It works fine when I change the  "not ="   to  an "='"  Sign.  But I do not understand why not = is not working.

%MACRO  Combine_and_Transpose(REG);

  %if %eval( "&Reg."  not = "ALL")  %then

  %let Group_vars = %STR(ACCOUNT_NAME);

  %Else %let Group_vars = %STR(REGION PU9 GROUP_NAME ACCOUNT_NAME INSUTYPE);

%Mend;

%Combine_and_Transpose(&REG.);

Run;

Error Message -

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:

       "MAS"  not = "ALL"

ERROR: %EVAL function has no expression to evaluate, or %IF statement has no condition.

ERROR: The macro COMBINE_AND_TRANSPOSE will stop executing.


Accepted Solutions
Solution
‎03-07-2014 02:01 PM
Super Contributor
Posts: 1,636

Re: Question on %IF not =


All Replies
Solution
‎03-07-2014 02:01 PM
Super Contributor
Posts: 1,636

Re: Question on %IF not =

try using "ne".

Contributor
Posts: 31

Re: Question on %IF not =

Thanks a lot ...   i like the NE  compared to  ^=   :smileygrin:  but both shud work i believe. ..

Wish sas had used the <> symbol Smiley Happy

Super User
Super User
Posts: 6,498

Re: Question on %IF not =

SAS does use the <> operator but it is NOT the same as the NE operator. 

In base SAS and IML it means take the maximum value. 

So result of 0 <> -3 is 0 .

SAS(R) 9.2 Language Reference: Concepts, Second Edition

Super User
Posts: 17,775

Re: Question on %IF not =

Super User
Super User
Posts: 6,498

Re: Question on %IF not =

Just put the NOT outside the comparison. Also %EVAL() is not needed.

Instead of %if %eval( "&Reg."  not = "ALL")  %then

use %if not ( "&Reg."  = "ALL")  %then

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 304 views
  • 0 likes
  • 4 in conversation