Or not being evaluated

Reply
Contributor
Posts: 74

Or not being evaluated

Why does SAS not evaluate the Or statment here?  How do I recode this so it will work?  The macro variables all resolve correctly.

IF WEEKDAY(&WOD.) = 1 THEN DO;

  IF ((listname NOT IN (&SUNLIST.))

       OR (listtype NOT IN (&LISTALL.)))

THEN DO;

ERROR_DESC = 'ERR_WORKLIST'; err1 = 1;

END;

ELSE do;

ERROR_DESC = 'NON_ERROR'; err1 = 0;

END;

END;

Thanks,

Super User
Posts: 5,372

Re: Or not being evaluated

While your conditions seem logical, they're not how SAS wants to see them.  (In fact, I couldn't even hazard a guess as to what SAS will do with them.)  A couple of changes probably fixes that:

IF NOT ((listname IN (&SUNLIST.)) 

       AND (listtype IN (&LISTALL.)))

THEN DO;

That should take care of it.

Good luck.

Super User
Posts: 19,194

Re: Or not being evaluated

Your code looks correct, but it may not be the logic you want.

I think you have to provide a sample of the logic you're after to help debug this. Sample input/output is preferable.

Respected Advisor
Posts: 4,828

Re: Or not being evaluated

A simplified version of your code works just fine. The problem must be with the value of the macro variables...

1    data _null_;

2    do listname = "A", "B";

3        do listtype = 1, 2;

4            IF ((listname NOT IN ("A"))

5                   OR (listtype NOT IN (1)))

6            THEN DO;

7                put listname listtype 'ERR_WORKLIST';

8                END;

9            ELSE do;

10               put listname listtype 'NON_ERROR';

11               END;

12           end;

13       end;

14   run;

A 1 NON_ERROR

A 2 ERR_WORKLIST

B 1 ERR_WORKLIST

B 2 ERR_WORKLIST

PG

PG
Super User
Posts: 11,144

Re: Or not being evaluated

What are the values of your sunlist and listall variables?

And what exactly do you mean by "Does not evaluate"?

Does this give you any clues?


%let sunlist = "Junk"  "Crap";
%let listall = "num" "char";
data junk;
input listname $ listtype $;
IF ((listname NOT IN (&SUNLIST.))
       OR (listtype NOT IN (&LISTALL.)))
THEN DO;
ERROR_DESC = 'ERR_WORKLIST'; err1 = 1;
END;
ELSE do;
ERROR_DESC = 'NON_ERROR'; err1 = 0;
END;

datalines;
junk num
Junk Num
Junk num
JUNK NUM
crap num
;
run;

Contributor
Posts: 74

Re: Or not being evaluated

This is what I am trying to do.

&sunlist is a long list of report names, &listall has just one value at this time.  I am comparing the value in the listname field I am reading in from a csv file to the hardcoded list in &sunlist.  So the error would be if the listname value is not = to the values in &sunlist or not equal to the value in &listall.

There is a different list for each day.

it does not appear that the or part of the if statement  is working.

Thanks,

Super User
Posts: 11,144

Re: Or not being evaluated

Give an EXPLICIT example of how it is "not working". The exact value of the macro variables involved, including any quotes,. the exact values of some of the listname and listtype variables compared, the actual results and the expected results.

I think a very likely cause, especially since you say a "hardcoded list" is case sensitivity.

"Word" is not equal to "word" or "WORD" due to case of the letters involved. "Report Name" is not equal to "Report  Name" due to extra space, and leading or trailing blanks can also cause things not to be equal.

Did you get the code to "work" before creating macro variables?

Respected Advisor
Posts: 4,828

Re: Or not being evaluated

You say "the error would be if the listname value is not = to the values in &sunlist or not equal to the value in &listall" but it is listtype that you compare to &listall...

PG

PG
Super User
Super User
Posts: 6,851

Re: Or not being evaluated

Given this explanation you can probably simplify your expression to a single IN () operator.

%let sunlist='A','B','C';

%let listall='D' ;

data ... ;

  if listname not in (&sunlist,&listall) then ...

  ...

run;

You also need to worry about the case of LISTNAME and &sunlist and &listall.  As coded in your example and mine the values must match exactly.

  if upcase(listname) not in (%upcase(&sunlist,&listall)) then ...

You also need to worry about the format for the values of SUNLIST and LISTALL macro variables that they could be properly used in the value list for the IN () operator.

Super User
Posts: 11,144

Re: Or not being evaluated

Also if your sunlist is defined as "reportname1 reportname2 reportname3" the comparison will fail because the text "reportname1" is not equal to the entire list.

Occasional Contributor
Posts: 15

Re: Or not being evaluated

From looking at your code and reading your description of the problem, I don't think your code is doing what you are trying to do.

     "So the error would be if the listname value is not = to the values in &sunlist or not equal to the value in &listall"

I think you are trying to do this,

If ((listname NOT IN (&SUNLIST.)) AND (listtype NOT IN (&LISTALL.)))

One way to check your logic is to negate it and flip the then else.

From your description it sounds like you want to do this:

IF WEEKDAY(&WOD.) = 1 THEN DO;

  IF listname IN (&SUNLIST.)
       OR listtype IN (&LISTALL.)

THEN DO;
ERROR_DESC = 'NON_ERROR'; err1 = 0;
END;

ELSE do;
ERROR_DESC = 'ERR_WORKLIST'; err1 = 1;
END;

To create what I think you want from the code above, 1) negate the conditions, 2) change ORs to ANDs and ANDs to ORs and 3) flip the then else.

So, the code as you present the problem should be

IF WEEKDAY(&WOD.) = 1 THEN DO;

  IF listname NOT IN (&SUNLIST.)
       AND listtype NOT IN (&LISTALL.)

THEN DO;
ERROR_DESC = 'ERR_WORKLIST'; err1 = 1;

END;

ELSE do;
ERROR_DESC = 'NON_ERROR'; err1 = 0;

END;

Gary

Ask a Question
Discussion stats
  • 10 replies
  • 307 views
  • 1 like
  • 7 in conversation