Solved
Contributor
Posts: 46

# else if

1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

42         ;

43         data amounts;

44         set new1;

45         if sum <150 then amount = 'lessthan150';

46         else if sum>150 and <500 then amount = 'to500'

_         ______ _

22        180    180

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,

a missing value, INPUT, PUT.

ERROR 180-322: Statement is not valid or it is used out of proper order.

47

48         else  amount = '>500';

49         run;

Hi Team

i am running the above query and i get the error.

any help would be great...

thanks..

Accepted Solutions
Solution
‎01-19-2015 01:21 AM
Super Contributor
Posts: 490

## Re: else if

```
46         else if sum>150 and <500 then amount = 'to500'
_         ______ _
22        180    180
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,
a missing value, INPUT, PUT.
ERROR 180-322: Statement is not valid or it is used out of proper order.

```

should be

else if sum>150 and sum<500 then amount = 'to500';

but as you defined 150 is belong to the third category >500', which is wrong

so you may defined it as

else if sum <= 500 then amount = 'to500';

All Replies
Solution
‎01-19-2015 01:21 AM
Super Contributor
Posts: 490

## Re: else if

```
46         else if sum>150 and <500 then amount = 'to500'
_         ______ _
22        180    180
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,
a missing value, INPUT, PUT.
ERROR 180-322: Statement is not valid or it is used out of proper order.

```

should be

else if sum>150 and sum<500 then amount = 'to500';

but as you defined 150 is belong to the third category >500', which is wrong

so you may defined it as

else if sum <= 500 then amount = 'to500';

Super User
Posts: 10,217

## Re: else if

What should happen when sum equals 150? Because that case would be specifically excluded by your condition. As Mohamed already suggested, omit the >150 comparison.

If you want to write a "between" construct, you can use

if 150 <= sum < 500 then amount = 'to500';

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 46