Help using Base SAS procedures

Using the 'or' statement

Accepted Solution Solved
Reply
Regular Contributor
Posts: 194
Accepted Solution

Using the 'or' statement

[ Edited ]

Hello,

 

I am trying to write code that will catch any fields that aren't within 3 specified values for buildingtype:  PUBLIC, PRIVATE, AND UNKNOWN.

 

I tried this:

 

data clean;
set have;
 btype_error=0;
  if btype ne 'PUBLIC'  or btype ne 'PRIVATE' or btype ne 'UNKNOWN' then btype_error=1;
run;

 

But, I'm getting btype_error=1 for all of the observations.

 

What am I doing wrong? Thanks.


Accepted Solutions
Solution
‎06-13-2017 11:54 AM
Super User
Posts: 5,495

Re: Using the 'or' statement

[ Edited ]

OR is incorrect.  For example, if the value is PUBLIC, then the comparison ne 'UNKNOWN' must be true.  Just change OR to AND.

 

Alternatively, you may find this easier to read (provided that you want to compare BTYPE each time, and not SCHTYPE):

 

if btype not in ('PUBLIC', 'PRIVATE', 'UNKNOWN') then btype_error=1;

View solution in original post


All Replies
Solution
‎06-13-2017 11:54 AM
Super User
Posts: 5,495

Re: Using the 'or' statement

[ Edited ]

OR is incorrect.  For example, if the value is PUBLIC, then the comparison ne 'UNKNOWN' must be true.  Just change OR to AND.

 

Alternatively, you may find this easier to read (provided that you want to compare BTYPE each time, and not SCHTYPE):

 

if btype not in ('PUBLIC', 'PRIVATE', 'UNKNOWN') then btype_error=1;

Regular Contributor
Posts: 194

Re: Using the 'or' statement

Posted in reply to Astounding
Thank you very much!
Regular Contributor
Posts: 194

Re: Using the 'or' statement

Posted in reply to Astounding

Yes, I want to compare btype every time.  schtype was a typo. I edited it and replaced it with btype.  Thanks!

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 129 views
  • 1 like
  • 2 in conversation