Hi Experts,
I am running a code and it is showing syntax error. I am unable to spot what is the mistake in the code. Can you please check and let me know?
proc sql;
create table File_for_the_ticket as
select a.*,
from work.final_file
where non_uk_PC = 0;
quit;
Error log:
28
29 proc sql;
30 create table File_for_the_ticket as
31 select a.*,
32 from work.final_file
____
22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, ',', -, /, <, <=, <>, =, >, >=, ?, AND, BETWEEN,
CONTAINS, EQ, EQT, FROM, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.
33 where non_uk_PC = 0;
_____
22
76
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, !, !!, &, *, **, +, ',', -, /, <, <=, <>, =, >, >=, ?,
AND, AS, BETWEEN, CONTAINS, EQ, EQT, FORMAT, FROM, GE, GET, GT, GTT, IN, INFORMAT, INTO, IS, LABEL, LE, LEN, LENGTH,
LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, TRANSCODE, ^, ^=, |, ||, ~, ~=.
ERROR 76-322: Syntax error, statement will be ignored.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
34 quit;
Use
select *
Instead
select a.*
I tried that way but still showing the same error. Please check the error message.
29 proc sql;
30 create table File_for_the_ticket as
31 select *,
32 from work.final_file
____
22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, ',', -, /, <, <=, <>, =, >, >=, ?, AND, BETWEEN,
CONTAINS, EQ, EQT, FROM, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.
33 where non_uk_PC = 0;
_____
22
76
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, !, !!, &, *, **, +, ',', -, /, <, <=, <>, =, >, >=, ?,
AND, AS, BETWEEN, CONTAINS, EQ, EQT, FORMAT, FROM, GE, GET, GT, GTT, IN, INFORMAT, INTO, IS, LABEL, LE, LEN, LENGTH,
LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, TRANSCODE, ^, ^=, |, ||, ~, ~=.
ERROR 76-322: Syntax error, statement will be ignored.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
34 quit;
Use this code:
29 proc sql;
30 create table File_for_the_ticket as
31 select *
32 from work.final_file
The comma in the first part of a select which is listing variables delimits variables (or statements creating variables). So when you use any variable followed by a comma the next thing expected is a variable or construction clause. You used
<variable> , from dataset. When SAS interprets as missing a variable following the comma as the From indicates the variable list is supposed to be ended.
To use a.*, which would mean all variables from the data set with an alias of A you would have to assign that alias as part of the from. Formally that is datasetname AS alias though a great many programmers will use an implied "as" and just provide the alias such as: "work.final_file a"
proc sql;
create table File_for_the_ticket as
select a.*
from work.final_file AS A
where non_uk_PC = 0
;
quit;
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.