New SAS User

Completely new to SAS or trying something new with SAS? Post here for help getting started.
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Sandeep77
Lapis Lazuli | Level 10

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;
1 ACCEPTED SOLUTION

Accepted Solutions
mleme
Fluorite | Level 6

Use 

     select *

Instead

    select a.*

View solution in original post

6 REPLIES 6
mleme
Fluorite | Level 6

Use 

     select *

Instead

    select a.*

Sandeep77
Lapis Lazuli | Level 10

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;
mleme
Fluorite | Level 6

Use this code:

 

29         proc sql;
30         create table File_for_the_ticket as
31         select * 
32         from work.final_file
Sandeep77
Lapis Lazuli | Level 10
Got it. Thank you!
ballardw
Super User

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;

 

Dianahemes
Fluorite | Level 6
How to Fix It: If a syntax error appears, check to make sure that the parentheses are matched up correctly. If one end is missing or lined up incorrectly, then type in the correction and check to make sure that the code can be compiled. Keeping the code as organized as possible also helps.

Regards,
Will

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 6 replies
  • 1800 views
  • 2 likes
  • 4 in conversation