BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
btenney
Calcite | Level 5

I keep receiving this error message: 

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, ',', -, /, <, <=, <>, =, >, ><, >=, AND, BY, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, TO, ^=, |, ||, ~=.
 
The code is: 
 
data ex7;
INFILE "12q19.character.txt"
dlm='09'x firstobs=2;
input HOUSE Y X1 X2 X3 X4 location $;
if location="intown" then
DO Zlocation1=0;
Zlocation2=0;
Zlocation3=0;
end;
else if location="inner suburbs" then
DO Zlocation1=1​;
Zlocation2=0​;
Zlocation3=0​;
end;
else if location="outer suburbs" then
DO Zlocation1=0;
Zlocation2=1;
Zlocation3=0;
end;
else
do
Zlocation1=0;
Zlocation2=0;
Zlocation3=1;
end;
x1location1=x1*Zlocation1;
x1location2=x1*Zlocation2;
x1location3=x1*Zlocation3;
run;
 
This is where the error message is: 
btenney_0-1617140399599.png

 

 
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Looks like there are gibberish characters before the semi-colon on some of the lines:

502   else if location="inner suburbs" then
503   DO Zlocation1=1?;
                     -
                     388
                     200
                     76
504   Zlocation2=0?;
                  -
                  388
                  200
                  76
505   Zlocation3=0?;
                  -
                  388
                  200
                  76
ERROR 388-185: Expecting an arithmetic operator.

ERROR 200-322: The symbol is not recognized and will be ignored.

ERROR 76-322: Syntax error, statement will be ignored.

506   end;

Also that is a very strange way to code your DO loop.  You have essentially coded an iterative DO loop with only one iteration.  Instead of using DO ZLOCATION1=0 to 2 or DO ZLOCATION1=1,3,4 you just have used DO ZLOCATION1=0. Normally when you only want to run the DO loop once you do NOT include a iterative variable in the DO statement. Instead just use DO without anything after it and set ZLOCATION1 the same way you are setting ZLOCATION2 and ZLOCATION3.

if location="intown" then DO;
  Zlocation1=0;
  Zlocation2=0;
  Zlocation3=0;
end;
else if location="inner suburbs" then DO;
  Zlocation1=1;
  Zlocation2=0;
  Zlocation3=0;
end;

From your logic it looks like you can eliminate the DO loops and the IF/THEN/ELSE statements and just calculate the 0/1 values as the result of boolean expressions.  Your current logic reduces to these three assignment statements.

Zlocation1=location="inner suburbs";
Zlocation2=location="outer suburbs";
Zlocation3=location not in ("intown" "inner suburbs" "outer suburbs");

 

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

Looks like there are gibberish characters before the semi-colon on some of the lines:

502   else if location="inner suburbs" then
503   DO Zlocation1=1?;
                     -
                     388
                     200
                     76
504   Zlocation2=0?;
                  -
                  388
                  200
                  76
505   Zlocation3=0?;
                  -
                  388
                  200
                  76
ERROR 388-185: Expecting an arithmetic operator.

ERROR 200-322: The symbol is not recognized and will be ignored.

ERROR 76-322: Syntax error, statement will be ignored.

506   end;

Also that is a very strange way to code your DO loop.  You have essentially coded an iterative DO loop with only one iteration.  Instead of using DO ZLOCATION1=0 to 2 or DO ZLOCATION1=1,3,4 you just have used DO ZLOCATION1=0. Normally when you only want to run the DO loop once you do NOT include a iterative variable in the DO statement. Instead just use DO without anything after it and set ZLOCATION1 the same way you are setting ZLOCATION2 and ZLOCATION3.

if location="intown" then DO;
  Zlocation1=0;
  Zlocation2=0;
  Zlocation3=0;
end;
else if location="inner suburbs" then DO;
  Zlocation1=1;
  Zlocation2=0;
  Zlocation3=0;
end;

From your logic it looks like you can eliminate the DO loops and the IF/THEN/ELSE statements and just calculate the 0/1 values as the result of boolean expressions.  Your current logic reduces to these three assignment statements.

Zlocation1=location="inner suburbs";
Zlocation2=location="outer suburbs";
Zlocation3=location not in ("intown" "inner suburbs" "outer suburbs");

 

Kurt_Bremser
Super User

Maxim 12: Make It Look Nice.

As posted, your code is hard to debug and maintain. This may have been caused by pasting the code into the main posting window. Use the "little running man" button right next to the one indicated for posting code:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

(</> is for posting logs and other fixed-width text, e.g. content of text infiles)

Next, replace the IF/THEN/ELSE IF chain with a SELECT block that better shows the purpose.

data ex7;
infile
  "12q19.character.txt"
  dlm='09'x
  firstobs=2
;
input HOUSE Y X1 X2 X3 X4 location :$13.;
select (location);
  when ("intown") do;
    Zlocation1 = 0;
    Zlocation2 = 0;
    Zlocation3 = 0;
  end;
  when ("inner suburbs") do;
    Zlocation1 = 1;
    Zlocation2 = 0;
    Zlocation3 = 0;
  end;
  when ("outer suburbs") do;
    Zlocation1 = 0;
    Zlocation2 = 1;
    Zlocation3 = 0;
  end;
  otherwise do;
    Zlocation1 = 0;
    Zlocation2 = 0;
    Zlocation3 = 1;
  end;
end;
x1location1 = x1 * Zlocation1;
x1location2 = x1 * Zlocation2;
x1location3 = x1 * Zlocation3;
run;

There were some undisplayable characters where the ERROR was indicated.

I also added an informat for the character variable. The $ sign on its own would lead to a defined length of 8, so the values "inner suburbs" and "outer suburbs" would be truncated during the read.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2828 views
  • 1 like
  • 4 in conversation