else if

Accepted Solution Solved
Reply
Contributor
Posts: 44
Accepted Solution

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';


View solution in original post


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: 7,832

Re: else if

Posted in reply to mohamed_zaki

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
Contributor
Posts: 44

Re: else if

Posted in reply to mohamed_zaki

Thanks Mohamed  it worked

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 338 views
  • 5 likes
  • 3 in conversation