turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- AND and OR statements in sas problem

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-02-2014 02:12 PM

How can this EXCEL statement be written in SAS

Excel version:

=IF(OR(AND(A<=X,ISBLANK(B)),(AND(A<=X,B<A))),1,0)

in Other words, if A<=X and B is blank then then variable value =1 OR if A<=X and B<1 then variable value =1 else variable value=c

I've used a SAS statement like this:

data want

let value $10:

iF A is le X and B ='' then value= ‘1’:

if A is le X and B lt A then values='1':

else value=0

these statements do not bring up correct results. How do use the OR statement correctly here? I think the error is in the implementation of OR.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-02-2014 02:26 PM

With SAS, TRUE is 1 and FALSE is 0, so your expression can be written:

**value = A<=X and (missing(B) or B<A);**

PG

PG

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-02-2014 02:34 PM

That doesn't seem like valid SAS code, I think you missed an else for one and a typo, value vs values.

Is this closer:

IF A le X and B ='' then value= 1;

ELSE if A le X and B lt A then value=1;

else value=0;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-02-2014 03:39 PM

What do you want to do if A is missing? Missing values are always less than anything else and you want to make sure you are getting expected results. If you don't want to assign 1 when A is missing you need to address that.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-02-2014 03:55 PM

What about this:

IF A ne. and A le X and B =. then value= 1;

ELSE if A ne. and A le X and B lt A then value=1;

else value=0;