BookmarkSubscribeRSS Feed
kvera40
Calcite | Level 5

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

 

2 REPLIES 2
mkeintz
PROC Star

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.

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ballardw
Super User

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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