I keep receiving this error message:
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");
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");
You need a semicolon after do.
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:
(</> 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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.