Desktop productivity for business analysts and programmers

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>,

Reply
Occasional Contributor
Posts: 5

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>,

I am trying to figure out what I am doing wrong when trying to add a comment. Here is the code i am running.. 

 

data tour1;
input Country $ 1-11 Nights AirCost LandCost Vendor $;
totalCost= airCost + landCost;
peakAir= ( airCost * 1.10) + 8;
nightCost= landCost / nights;

if country = 'Greece' then NewtotalCost = (totalCost * 0.02) + 748 and comment 'sell out fast';
cards;
Japan 8 982 1020 Express
Greece 12 585 748 Express
New Zealand 16 1368 1539 Southsea
Ireland 7 787 628 Express
Venezuela 9 426 505 Mundial
Italy 8 852 598 Express
Russia 14 1106 1024 A-B-C
Switzerland 9 816 834 Tour2000
Australia 12 1299 1169 Southsea
Brazil 8 682 610 Almeida
;
run;

proc print data=tour1;
title 'MAD Echo Print Tour Data';
run;

 

and here is the error message I am receiving. 

 

22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>,
=, >, ><, >=, AND, EQ, GE, GT, LE, LT, MAX, MIN, NE, NG, NL, OR, ^=, |, ||, ~=.

 

Please help

 

Super User
Posts: 787

Re: ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <,

[ Edited ]

It appears you need to change

 

if country = 'Greece' then NewtotalCost = (totalCost * 0.02) + 748 and comment 'sell out fast';

 

 

to

 

if country = 'Greece' then do;

    NewtotalCost = (totalCost * 0.02) + 748;

    comment='sell out fast';

end;

 

 

In an "if ...  then ..." statement the then clause can only be a single action.  You wanted multiple actions, so the then clause needs to start a do group which contains the multiple desired actions.

 

 

Editted addition.  The error message might be a bit misleading because, for syntax purposes, the comment variable was expected to be followed by an operator, as in:

 

if country = 'Greece' then NewtotalCost = (totalCost * 0.02) + 748 and comment = 'sell out fast';

 

But that would have made the then-clause into a logical expression, testing the "truth" of these two expressions:

                     (totalcost* 0.02+748)

              and

                    (comment='sell out fast')

 

If both of those expressions were non-zero, then newtotalcost would = 1.   But it wouldn't have anything to do with your apparent intentions.

 

Grand Advisor
Posts: 10,192

Re: ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <,

[ Edited ]

For future reference, it is preferable to copy code with the error message from LOG and paste into a code box opened with the forum {i} icon. The log often contains information in the form of an underscore as to the location of the reported error. If you paste the log results into a code box then the formatting from the log is retained and the underscore appears in the correct relative position. Also including the code from log reduces likelihood of pasting code other than was actually run to generate the error.

Ask a Question
Discussion stats
  • 2 replies
  • 115 views
  • 1 like
  • 3 in conversation